Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Detection does not work with JS ES Modules #253

Open
robertfmurdock opened this issue Jan 27, 2025 · 2 comments
Open

Environment Detection does not work with JS ES Modules #253

robertfmurdock opened this issue Jan 27, 2025 · 2 comments

Comments

@robertfmurdock
Copy link

When this module is used as a dependency in a project that uses the setting "compilerOptions { target = "es2015" }", suddenly environment variables aren't available to the application via MultiplatformSystem.readEnvironmentVariable.

It looks like when the JS code tries to determine the environment, it uses a raw 'require'. I believe this is causing an error when inside of an mjs context, causing the system to assume its running in a browser context, even though it is not.

Discovered this after switching a project based on Clikt to use ESM.

@ajalt
Copy link
Owner

ajalt commented Jan 28, 2025

So the import code is actually rather complicated in order to support different environments and avoid compiler warnings: https://github.com/ajalt/mordant/blob/master/mordant/src/jsMain/kotlin/com/github/ajalt/mordant/internal/JsCompat.kt

Do you have any suggestions on how to support that module type?

@robertfmurdock
Copy link
Author

I think the async style require might work? though I'm not sure how well that would fit into you existing code. I'll think on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants