Another question: Is there any way I can get acces...
# javascript
t
Another question: Is there any way I can get access to a package from NPM which is purely ESM. Im currently looking at this package: https://www.npmjs.com/package/bcp-47
👌 1
I guess i can use an older version which is not ESM only. But that isn't really great.
t
Could you share your current typings?
v
Have you by any chance figured out how to use the ESM-only packages in Kotlin/js?
t
It's supported and it works You can find multiple examples in https://github.com/JetBrains/kotlin-wrappers If you have problems with concrete library - please describe your concrete problem
v
would appreciate a pointer to a specific example out of those packages! will describe my problem below
• I’m trying to use alfy - https://github.com/sindresorhus/alfy • portions of gradle file:
Copy code
plugins {
    kotlin("js") version "1.7.10"
}
...

dependencies {
...
    implementation(npm("alfy", "1.0.0"))
...
}

kotlin {
    js(IR) {
        binaries.executable()
        nodejs {

        }

    }
}
• alfy type definitions:
Copy code
@JsModule("alfy")
@JsNonModule
external object alfy {
    val input: String
    fun output(items: List<AlfredResult>)
}
when compiled & trying to run I get the following error:
Copy code
[22:50:30.733] ERROR: KAutocomplete the world[Script Filter] Code 1: node:internal/modules/cjs/loader:1148
      throw err;
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/vlad/coding/knowledge/autocomplete-the-world-kt/build/js/node_modules/alfy/index.js from /Users/vlad/coding/knowledge/autocomplete-the-world-kt/build/js/packages/autocomplete-the-world/kotlin/autocomplete-the-world.js not supported.
Instead change the require of index.js in /Users/vlad/coding/knowledge/autocomplete-the-world-kt/build/js/packages/autocomplete-the-world/kotlin/autocomplete-the-world.js to a dynamic import() which is available in all CommonJS modules.
    at /Users/vlad/coding/knowledge/autocomplete-the-world-kt/build/js/packages/autocomplete-the-world/kotlin/autocomplete-the-world.js:5:29
    at Object.<anonymous> (/Users/vlad/coding/knowledge/autocomplete-the-world-kt/build/js/packages/autocomplete-the-world/kotlin/autocomplete-the-world.js:21:2) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v17.5.0
t
would appreciate a pointer to a specific example out of those packages!
will describe my problem below
kotlin-node
Looks like Kotlin Gradle plugin required to solve
require
problem 🙂
v
hmm, it does not seem to depend on any external dependencies, or do you mean that the node internal modules would be esm only? and which plugin are you referring to? I have
Copy code
plugins {
    kotlin("js") version "1.7.10"
}
and none of the other plugins in the package seem relevant?
@turansky would appreciate any further thoughts on this!
t
We need simple custom plugin which will solve this problem for both platforms (Browser and Node)
Current plan - add it in KFC - https://github.com/turansky/kfc-plugins cc @Sergei Grishchenko
@Vladyslav Sitalo Do you use Node declarations from Kotlin Wrappers?