When I try to create a context with ```val LoginCo...
# react
i
When I try to create a context with
Copy code
val LoginContext = createContext<LoginContextData>()
I get the following error
When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModule
What's wrong?
b
kotlin react wrappers uses
commonJs
for module types (I am not a js expert so sorry for wrong wording). Your project is probably using a different one. I solved the issue in my project by setting the module type to
AMD
. This is what I added to my `build.gradle.kts`:
Copy code
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target.AMD

tasks.withType<KotlinJsCompile> {
    // See <https://github.com/amdjs/amdjs-api/blob/master/AMD.md>
    kotlinOptions.moduleKind = AMD
}
Also see: https://kotlinlang.org/docs/reference/js-modules.html
👍 1
t
commonJs
for wrappers musn’t limit final module kind
Where declared
createContext
method?
i
Thanks for the helpful answers. Adding
useCommonJs()
to my build.gradle.kts worked for me:
Copy code
kotlin {
    target {
        browser {
        }
        useCommonJs()
    }
}
i