I have KMP library which jsMain depends on bignumb...
# javascript
r
I have KMP library which jsMain depends on bignumber.js through npm:
Copy code
sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(npm("bignumber.js", "9.0.2"))
            }
        }
    }
I published my KMP library to my private maven and use it in my another KMP project:
Copy code
sourceSets {
    val commonMain by getting {
      dependencies {
        implementation("com.calculation.multiplatform:MultiplatformBigDecimal:1.0.0")
      }
    }
  }
Then I build js package in my KMP project use
./gradlew jsBrowserProductionWebpack
command. The problem is that I cannot see peerDependencies on MultiplatformBigDecimal and bignumber.js
b
Nor you should. You can't see peer dependencies in regular js project tioy
Optional and peer dependencies indicate that the lib uses them, but expect the consumer to apply them
It's similar to how runtimeOnly works in gradle
r
Ok, I'll test in js and then will give you a feedback, thanks.
Now the problem is when I use the js package in js project, it cannot find 'bignumber.js' if I don't add it explicitly.
@Big Chungus 👆
b
What's the package.json of that node consumer module?
Or are you just trying to run kjs output directly via node?
Is your project OSS? Setting up npm lib properly has quite a few moving pieces, so it'd be best if I could just have a look at your setup and point out all the issues.
Most likely your issues are not even kjs related
r
In JS project
Copy code
{
  "name": "test-abacus-bignumber",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "abacus": "^0.0.17-alpha.29212"
  }
}
The abacus is a KMP project and the project will publish a js package. In abacus project
Copy code
sourceSets {
    val commonMain by getting {
      dependencies {
        implementation("com.calculation.multiplatform:MultiplatformBigDecimal:1.0.0")
      }
    }
  }
MultiplatformBigDecimal is another KMP library. In MultiplatformBigDecimal project
Copy code
kotlin {
    sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(npm("bignumber.js", "9.0.2"))
            }
        }
    }
}
Now back to JS project, I'll encounter <cannot find module 'bignumber.js'>.
If I add the bignumber.js in JS project explicitly, it works. But abacus js package should have a dependency for bignumber.js so that there is no need to add it explicitly in JS project.
b
You need to add bignumber.js as api dependencies instead of implementation, otherwise it will not be accessible as transitive dependency to consumers
Also make sure that your abacus uses binaries.library() instead of executable()
r
Get it, thanks