(<https://kotlinlang.org/docs/tutorials/javascript...
# javascript
a
Seems like this doc is a few years out of date. =(
The JS code in the doc is how it looked like before Kotlin 1.1 if memory serves me right
v
Thanks! Still can’t solve the problem. At the moment, I’m thinking that problem in VueJS / Webpack configs. It’s not my field of expertise, so keep diving.
a
If it’s a toy project feel free to share the code with me. Maybe I’ll be able to spot the problem
v
Thanks for the support! I’ve managed to fix this problem by alter the resulting JS. I would automate this patch to include in a library build step
1. Put
Copy code
export default
in the beginning of the SharedCode.js file It should look like:
Copy code
export default (function (_, Kotlin) {
2. Replace
Copy code
module.exports
in the end of the file with
Copy code
{}
It should look like:
Copy code
}({}, require('kotlin')));
It’s kind a hack, but it works for now. I hope that Kotlin JS would adopt modern JS modules.
Btw, it’s not a toy project. It’s a production library to share some Kotlin logic between Android and Web App
a
Congratulations on making it work 😃 It seems that the root of you problems is that you are using ES6 features, in particular ES modules. That's different from Common JS. At the moment we don't support any ES6 features, including ES modules. =(
We do consider emitting ES6 directly, but at the moment we are finishing a huge rewrite of the compiler, so no timeline unfortunately
If you want to mix ES5 and ES6 together you will run into some obstacles. The module system issue is one of them.
Another issue is static member inheritance in ES6: https://youtrack.jetbrains.com/issue/KT-32161
But in theory it should be possible.
So good luck with your project and feel free to ask for help if you run into other issues.