how do I export my kotlin functions and import the...
# javascript
a
how do I export my kotlin functions and import them in a nodejs project? The docs have me confused about this. I think something gets messed up because I use kotlin packages. more info in 🧵
example of koltin code:
Copy code
package com.composables

@OptIn(ExperimentalJsExport::class)
@JsExport
fun svgToComposeImageVector(svg: String, variableName: String = "Output"): String {
}
I build my lib using:
jsNodeDevelopmentLibraryDistribution
then copy paste the generated lib folder into my nodejs app I cannot figure out how to import it. I see this weird code generated in the generated js file:
Copy code
function $jsExportAll$(_) {
    var $com = _.com || (_.com = {});
    var $com$composables = $com.composables || ($com.composables = {});
    $com$composables.svgToComposeImageVector = svgToComposeImageVector;
  }
  $jsExportAll$(_);
and I can't figure out how to import the
svgToComposeImageVector
function
ok figured this out. I did not understand what nodejs types are and that they were different to packaging formats. ended up exporting my lib using the gradle task mentioned above, then copied to my nodejs repo (but outside of the app itself). did
npm i /path/to/exported/kotlin/lib
and I can use it as a normal installed module
e
The
_
symbol is the root namespace of the exported library. I suppose you're using CommonJS.
a
@Alex Styl is it a monorepo?
a
@Artem Kobzar no. the lib is a different project if that's what you are asking
a
Yes, it is. So, yep the
npm i /path/to/exported/kotlin/lib
is the best solution for the local development
e
I'd also play around with
npm link
, which creates a symbolic link and allows you (in theory, but doesn't always keep its promise) to simply compile the distribution without having to re-install each time. It's still not the best solution tho. That's why I prefer monorepos with npm workspaces.
1