How are we supposed to use an NPM dependency using...
# javascript
j
How are we supposed to use an NPM dependency using the kotlinjs plugin ? Are we supposed to import it in the html or will it be somehow automagically bundled in one big js ?
i
It is bundled in one big js via webpack in new
js
plugin You need to add only it to
index.html
j
Ok that's what I thought. Any idea what I am doing wrong in https://github.com/jdemeulenaere/kotlin-pixijs ? I am just trying to get started and make the "Setting up" section of https://github.com/kittykatattack/learningPixi#setting-up work 🙂 I tried to use dukat to generate the external definitions but it has a lot of failures during compilation (and I don't mind writing the external definitions by myself first). Thanks!
Error in the console:
Uncaught ReferenceError: sayHello is not defined
i
I think, that problem is in
external
declarations, you can just see what dukat generate to you, especially pay attention on the first annotations
@JsModule
and
@JsQualifier
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-module/index.html and https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-qualifier/index.html) I think it should be something like
Copy code
@file:JsModule("PIXI")
@file:JsQualifier("utils")
package PIXI.utils

external fun sayHello(type: String)
j
If I add those annotations then I get another kind of error:
When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModule
i
It is because there is
UMD
module system for Kotlin/JS by default which includes plain non modular js You can add
useCommonJs
in
target{}
block Or try to add
@file:JsNonModule
to external declaration file
j
useCommonJs fixed the problem 🙂 Thanks!
❤️ 1