Pepijn de Vos
05/13/2021, 5:58 PM@file:JsModule("react-plotly.js")
@file:JsNonModule
import react.*
@JsName("Plot")
external val reactPlot: RClass<dynamic>
But getting:
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `Welcome`.
in Welcome react.development.js:315
React 3
child_5 sampleproject.js:20925
child_6 sampleproject.js:20931
invoke_100 sampleproject.js:20934
render_0 sampleproject.js:25196
invoke_103 sampleproject.js:21108
factory_40 sampleproject.js:21164
buildElements sampleproject.js:21020
render_1 sampleproject.js:21129
render sampleproject.js:21132
React 13
render_0 sampleproject.js:24780
render$default sampleproject.js:24785
invoke_129 sampleproject.js:25057
factory_45 sampleproject.js:25070
(Async: EventHandlerNonNull)
main sampleproject.js:25010
<anonymous> sampleproject.js:25508
<anonymous> sampleproject.js:3
<anonymous> sampleproject.js:15
<anonymous> sampleproject.js:25490
js sampleproject.js:707
__webpack_require__ sampleproject.js:30
0 sampleproject.js:719
__webpack_require__ sampleproject.js:30
<anonymous> sampleproject.js:94
<anonymous> sampleproject.js:97
webpackUniversalModuleDefinition sampleproject.js:9
<anonymous> sampleproject.js:10
Bradleycorn
05/14/2021, 7:30 PMpackage.json
files have a few problems:
1. they have dependencies with “hardcoded” absolute file paths, like: "kotlin": "file:/Users/brad.ball/dev/multiplatform/new/wager-utils/build/js/packages_imported/kotlin/1.5.0",
2. the dependencies list contains entries for kotlin-test-js-runner
and kotlin-test
. Why would those be dependencies for a published package? Seems like at best they should be devDependencies.
With the hard coded file paths, you can’t really publish the package or use it anywhere but on the machine where it was generated…
The full package.json output is included in the replies thread…
Am I doing something wrong? I have a pretty standard gradle config, haven’t really changed much from what was produced by IntelliJ when creating the project. (edited)Jonathan Smith
05/14/2021, 9:48 PMRob Elliot
05/15/2021, 9:42 AMdwursteisen
05/15/2021, 10:37 AMmpp.js {
this.browser {
this.webpackTask {
this.compilation.kotlinOptions {
this.sourceMap = true
this.sourceMapEmbedSources = "always"
this.freeCompilerArgs += listOf("-Xopt-in=kotlin.ExperimentalStdlibApi")
}
}
}
this.binaries.executable()
}
• I'm trying to expose one method of my kotlin code and using it in my webpage.
package my.module
@JsExport fun startCube() { // ... }
• I'm trying to import this module from my index.html
. And it's not working 🤔
<script type="module">
import './my-module.js'; // the path is correct
</script>
• I got this error message :
Uncaught TypeError: Cannot set property 'my-module.js' of undefined
at webpackUniversalModuleDefinition (minigdx-docs.js:9)
• By looking at the code, I see that the module UMD "module system" try to start and load the module but failed to do so: root["my-module"] = factory(); // root is undefined
• I look in the Kotlin/JS documentation and how javascript module is working but I failed to understand what's wrong 🤔 (I far to be at ease in the javascript ecosystem)
• &TLDR: Do you have any advise, example to load a kotlin js module from a browser?Bas Verlooy
05/18/2021, 10:02 AMSlackbot
05/18/2021, 10:50 AMAndrey Ivanov
05/18/2021, 12:05 PMexternal fun <T> import(path: String): Promise<T>
or
external fun <dynamic> import(path: String): Promise<dynamic>
I try to use like this:
val SomePage = rLazy<dynamic> {
{ import<dynamic>("./somePage.js") }
}
I get the error:
Type mismatch.
Required:
RClass<TypeVariable(P)>
Found:
() → Promise<dynamic>
Why? I don't understand by the signature, I give him a lambda and he sees a promise inside the lambda.jmfayard
05/18/2021, 1:51 PM./gradlew jsNodeRun
Any pointers on how I could publish it on npmjs.org
so that people can install it with $ npm install -g kotlin-cli-starter
https://github.com/jmfayard/kotlin-cli-starterIan Alexander
05/18/2021, 10:22 PMCannot find module 'shared' or its corresponding type declarations.
The module is imported to the web project with "shared": "file:../build/js/packages/shared"
and into the javascript file with import { Platform } from 'shared';
Any idea where I may be going wrong?Aleksandar Milojević
05/20/2021, 6:24 AMimport kotlin.js.JsExport
@JsExport
fun helloWorld(): String {
return "Hello World"
}
setup in build.gradle.kts is
js(IR) {
browser {
}
binaries.executable()
}
After importation generated files in VCS, my kotlin function is not visible (Uncaught ReferenceError: helloWorld is not defined)
and generated files areHywel Bennett
05/20/2021, 10:08 AMTomas Kormanak
05/20/2021, 11:28 AM@JsModule("botui")
external class BotUI(name: String) {}
val bot = BotUI("test")
and I am getting error $module.$botui is not a constructor
botui module exports only one class as a default. Should I use different approach when module has only default export?Robert Jaros
05/20/2021, 1:41 PMUncaught SyntaxError: raw bracket is not allowed in regular expression with unicode flag
in kotlin.js:44848
probably with this code:
fun validateEmail(value: String): Boolean {
return value.matches("^([a-zA-Z0-9\\-_.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z\\-0-9]{2,}))$".toRegex())
}
Ilya Kalibrov [JB]
05/20/2021, 3:42 PMEthan Davidson
05/20/2021, 8:26 PMVincent Le
05/20/2021, 8:58 PMBig Chungus
05/23/2021, 9:07 PMimport "some/side/effect.js
in javascript?Tarun Chawla
05/24/2021, 6:53 AMDarren Bell
05/24/2021, 9:29 AMMrPowerGamerBR
05/24/2021, 1:31 PMRob Murdock
05/24/2021, 3:29 PMDeactivated User
05/25/2021, 9:44 AMjsBrowserProductionWebpack
gradle task doesn't update the distributions js file sometimes when in watch mode -t
?Robert Jaros
05/25/2021, 11:20 AMbuild.gradle.kts
doesn't compile. What happened?Tomas Kormanak
05/26/2021, 8:55 AMREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
I think I understand the issue itself, but I don't get why it started this morning (yesterday builds were ok, we upgraded to Kotlin 1.5.0 and webpack 5 couple weeks ago) Any idea?willyrs
05/28/2021, 10:58 AMjs("js", IR) {
browser()
binaries.executable()
useCommonJs()
}
and I'm using compileProductionExecutableKotlinJs to create the .js and d.ts that I copy to a typescript react project, but the js is super large (near 4mb)Big Chungus
05/29/2021, 2:37 AMShabinder Singh
05/30/2021, 11:19 AM"""ytInitialPlayerResponse\s*=\s*(\{.+?\})\;var meta""".toRegex()
*ERROR*(only in Kotlin/JS):
SyntaxError: Invalid regular expression: /ytInitialPlayerResponse\s*=\s*(\{.+?\})\;var meta/: *Invalid escape*
at <global>.new RegExp(<anonymous>)
However this same regex works fine online in a Regex Editor/Tester , link: https://regex101.com/r/WZT1Pr/1/
Any Help would be Appreciated!Robert Munro
05/31/2021, 10:37 AM@Serializable
data class ResponseDomain constructor(
val payload: List<Domain> = listOf(),
val errors: List<ErrorDomain> = listOf()
)
where domain is a kotlin interface that all the domain data obects implement and they are serialized using kotlin serialization(polymorphic)
In my frontend I fetch the url like so:
val response = window
.fetch("$BASE_URL/playlists")
.await()
.json()
.await()
which has a payload of List<PlaylistDomain>
@Serializable
data class PlaylistDomain constructor(
val id: Long? = null,
val title: String,
val items: List<PlaylistItemDomain> = listOf(),
...
) : Domain
but casting back to ResponseDomain fails
(response as ResponseDomain)
with and Illegal cast
error
should i just send the response as text/plain (not application/json) and use kotlin deserialisation to get a ResponseDomain?
seems like since the browser parses my json to json object i seem to not be able to cast to my kotlin object type - obvs i dont want to map the whole thing from json to domain manually but in the kotlin js tutorial (the video browser one) they map the response as a cast (response as Video
). maybe it only works for simple objects?Robert Munro
06/01/2021, 8:42 AMimplementation(npm("kotlinx-serialization-kotlinx-serialization-core-jslegacy", "1.4.2-RC1"))
and i get error:
Module 'kotlinx-serialization-kotlinx-serialization-core-jsLegacy' not found
> Task :remote:jsBrowserDevelopmentWebpack
do i have to install npm or something to make this work on github actions? or is there some github action i need to use to build kotlinJS on github actions?
this is my github actions yaml - the js lib is built and copied to a jar as a resource
https://github.com/sentinelweb/cuer/blob/ab00c7a7cd969eafa72b0d28bc5ba5c5c3e099d3/.github/workflows/android.ymlRobert Munro
06/01/2021, 8:42 AMimplementation(npm("kotlinx-serialization-kotlinx-serialization-core-jslegacy", "1.4.2-RC1"))
and i get error:
Module 'kotlinx-serialization-kotlinx-serialization-core-jsLegacy' not found
> Task :remote:jsBrowserDevelopmentWebpack
do i have to install npm or something to make this work on github actions? or is there some github action i need to use to build kotlinJS on github actions?
this is my github actions yaml - the js lib is built and copied to a jar as a resource
https://github.com/sentinelweb/cuer/blob/ab00c7a7cd969eafa72b0d28bc5ba5c5c3e099d3/.github/workflows/android.ymlturansky
06/01/2021, 9:04 AMRobert Munro
06/01/2021, 9:15 AMjsMain
implementation(npm("kotlinx-serialization-kotlinx-serialization-core-jslegacy", "1.4.2-RC1"))
without it i get an eror on the page saying the lib is missing. or similar fail for webpack as above.
or should i add you plugin declaration?turansky
06/01/2021, 9:44 AMserialization-core.js
located inside runtime jarRobert Munro
06/01/2021, 9:46 AMval commonMain by getting {
dependencies {
implementation(project(":shared"))
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$ver_kotlinx_datetime")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$ver_kotlinx_serialization_core")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$ver_kotlinx_serialization_core")
implementation("io.ktor:ktor-client-core:$ver_ktor")
implementation("io.insert-koin:koin-core:$ver_koin")
}
}
and
val jsMain by getting {
dependencies {
implementation(npm("kotlinx-serialization-kotlinx-serialization-core-jslegacy", "1.4.2-RC1"))
implementation("org.jetbrains.kotlinx:kotlinx-datetime-js:$ver_kotlinx_datetime")
implementation("org.jetbrains:kotlin-react:17.0.1-pre.148-kotlin-1.4.21")
implementation("org.jetbrains:kotlin-react-dom:17.0.1-pre.148-kotlin-1.4.21")
implementation(npm("react", "17.0.1"))
implementation(npm("react-dom", "17.0.1"))
implementation("org.jetbrains:kotlin-styled:5.2.1-pre.148-kotlin-1.4.21")
implementation(npm("styled-components", "~5.2.1"))
implementation(npm("react-youtube-lite", "1.0.1"))
implementation(npm("react-share", "~4.2.1"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
}
}
turansky
06/01/2021, 1:25 PMimplementation(npm("react", "17.0.1"))
implementation(npm("react-dom", "17.0.1"))
implementation(npm("styled-components", "~5.2.1"))
kotlinx-serialization-kotlinx-serialization-core-jslegacy
(version 1.4.2-RC1
is invalid)Robert Munro
06/02/2021, 8:30 AM