Never exported an enum before, so I've tried in my...
# javascript
e
Never exported an enum before, so I've tried in my MP project. This compiles fine from
commonMain
. Weren't enum exports prohibited?
a
Pfff .. I updated kotlin and yeah, no warning. But yeah ... I also read that they were prohibited. What would be a plan B then, if not enums ? What's the best practice ?
e
@AndreiBogdan that's actually a good question. Being I've never exported/used enums in my MPP as of now, I'd also like to understand what's the general consensus
a
Export enums should be okay. The only problem is to define external enums, in the new 1.9.0 Kotlin
a
Perfect. THank you very much !
i also have another issue ....
Copy code
@JsExport
object SharedUserManagerJs {

    fun saveUserToken(userToken: String?) {
        SharedUserManager.saveUserToken(userToken)
    }
}
this can not be found by my React colleague when importing the library
there are 2
object
classes that i exported, neither are visible to him in the web app code ...
why is that ?!
e
Thanks @Artem Kobzar! I think docs need to be updated to remove the
It is currently prohibited to export the following kinds of declarations:
• enum classes
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-export/
👀 1
@AndreiBogdan are you exporting using CommonJS modules or native ES modules? I can see it generates the correct JS code
Copy code
function SharedUserManagerJs() {
  SharedUserManagerJs_instance = this;
}
protoOf(SharedUserManagerJs).saveUserToken = function (userToken) {
  println(userToken);
};
a
Copy code
js(IR) {
    moduleName = "kmm-lib"
    nodejs {
        binaries.library()
    }
    useCommonJs()
}
is that why? because i'm using
useCommonJs()
?
what's the other option, if not
useCommonJs()
?
to be frank, i'm not 100% sure what useCommonJs() does 😄 😄 perhaps you could elucidate this mistery as well a bit 😄
e
https://en.wikipedia.org/wiki/CommonJS explains what it is pretty well. the other option is
useEsModules
. It seems to me ES modules are what the future of Node is anyway, and maybe what Kotlin will aim to get better at (correct me if I'm wrong on this tho).
React colleague
Mmm, why are you using
Copy code
nodejs {
  binaries.library()
}
? Shouldn't you target the browser?
a
hmm, so what's the other option besides useCommonJs() then ?
I'm using binaries.library() 'cause i just need to expose the business layer to the react web app. We've already got a web app setup, they're doing their own tuff there, i just need to expose some logic for them. same as i'm doing for iOS in fact.