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

Supoort EsModule when target in node.js #345

Open
sheng-ri opened this issue Jun 20, 2024 · 4 comments
Open

Supoort EsModule when target in node.js #345

sheng-ri opened this issue Jun 20, 2024 · 4 comments

Comments

@sheng-ri
Copy link

  • Exam code here
     SystemFileSystem.list(Path("./")).forEach {
         println(it)
    }
  • Using kotlin 2.0.0 then modify gradle.build.kts
  js {
          useEsModules()
          nodejs {}
          binaries.executable()
      }
  • then run jsNodeRun, it will shows
UnsupportedOperationException: Module 'os' could not be imported
    at os$delegate$lambda (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/nodeModulesJs.kt:27:18)
    at UnsafeLazyImpl.protoOf.get_value_j01efc_k$ (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/src/kotlin/util/Lazy.kt:81:26)
    at get_os (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/src/kotlin/util/Lazy.kt:44:93)
    at _init_properties_FileSystemNodeJs_kt__m4c3u (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/FileSystemNodeJs.kt:127:22)
    at get_SystemFileSystem (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/kotlinx-io-kotlinx-io-core.mjs:1787:3)
    at main (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/common/src/generated/_Collections.kt:12:25)
    at mainWrapper (file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/kotlin-js-demo.mjs:45:3)
    at file:///F:/demo/build/js/packages/kotlin-js-demo/kotlin/kotlin-js-demo.mjs:47:1
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at ModuleLoader.import (node:internal/modules/esm/loader:316:24)
@fzhinkin
Copy link
Collaborator

@sheng-ri thanks for reporting!

@lppedd
Copy link
Contributor

lppedd commented Jun 21, 2024

kotlinx-io uses hardcoded requires (see nodeModulesJs.kt), so there is no easy solution.

Real solution is KT-47038.

@whyoleg
Copy link
Contributor

whyoleg commented Jun 21, 2024

I do think that for kotlinx-io real and simple solution for now would be to just extract FS support to separate module, and so this module will provide FS for nodejs only without any hacks.

AFAIK there was some issue which mentions that, so may be that could be done earlier

WDYT?

@fzhinkin
Copy link
Collaborator

fzhinkin commented Jun 21, 2024

AFAIK there was some issue which mentions that

#319

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

No branches or pull requests

4 participants