I have built a Kotlin multiplatform library and published it to bintray. When trying to include it in a sample node.js application it will be able to find the dependency, but compiling will fail with the following exception:
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module 'storyblok-mp-sdk'
Require stack:
- /Users/.../storyblok-mp-SDK/nodejsapp/node/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /Users/.../storyblok-mp-SDK/nodejsapp/node/index.js:5:48
at Object.<anonymous> (/Users/.../storyblok-mp-SDK/nodejsapp/node/index.js:18:2)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/.../storyblok-mp-SDK/nodejsapp/node/index.js'
]
}
It looks as if the dependency itself is correctly downloaded and also processed during compilation (as it is available in the build directory as js file). But even though things seem to be in place the issue still occurs.
The whole sample project is was published at this branch here: https://github.com/mikepenz/storyblok-mp-SDK/tree/feature/nodejssample/nodejsapp
To keep things simple I tried to keep the build.gradle
as simple as possible
buildscript {
...
}
apply plugin: 'kotlin2js'
apply plugin: 'kotlin-dce-js'
repositories { ... }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
implementation "com.mikepenz:storyblok-mp-sdk-js:0.0.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.3"
}
compileKotlin2Js.kotlinOptions {
moduleKind = "umd"
outputFile = "node/index.js"
}
task npmInit(type: Exec) {
commandLine "npm", "init", "-y"
}
task npmInstall(type: Exec) {
commandLine "npm", "install", "kotlin", "kotlinx-coroutines-core", "express", "--save"
}
task npmRun(type: Exec) {
commandLine "node", "node/index.js"
}
npmRun.dependsOn(build)
All resources I could find seem very vague on how to properly configure the project. Removing the dependency itself and not referencing a class from the dependency seems to work. So the general project setup should be ok as far as I could say