kotlinx-io
kotlinx-io copied to clipboard
Supoort EsModule when target in node.js
trafficstars
- 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)
@sheng-ri thanks for reporting!
kotlinx-io uses hardcoded requires (see nodeModulesJs.kt), so there is no easy solution.
Real solution is KT-47038.
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?
AFAIK there was some issue which mentions that
https://github.com/Kotlin/kotlinx-io/issues/319