Hello everyone! :wave: I currently have a React ap...
# javascript
s
Hello everyone! 👋 I currently have a React app using typescript and I wanted to integrate a KotlinJS package. I have a KMP module which I build as a npm package using a wrapper module. KMP Core module => KMP shared-js module ( see comments for generated package.json ) When I
yarn add
the root package, it execute correctly. Now I have 2 questions… how can I set the root package.json’s version? Currently it always generate to
unspecified
. And when I try to import one of the exported class, I have this error:
Cannot find module or its corresponding type declarations.
Any tips on what I did wrong or what I could do to make it work? Thanks 🙂
This is the generated root package.json
Copy code
{
  "name": "42bieres",
  "version": "unspecified",
  "private": true,
  "workspaces": [
    "packages/42bieres-core",
    "packages/42bieres-core-test",
    "packages/42bieres-shared-js",
    "packages/42bieres-shared-js-test",
    "packages_imported/Kotlin-DateTime-library-kotlinx-datetime-js-ir/0.3.0",
    "packages_imported/kotlin/1.6.20-M1",
    "packages_imported/kotlin-test-js-runner/1.6.20-M1"
  ],
  "resolutions": {},
  "devDependencies": {},
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
And the shared-js package.json which contains all generated code
Copy code
{
  "name": "42bieres-shared-js",
  "version": "42.0.0",
  "main": "kotlin/42bieres-shared-js.js",
  "devDependencies": {
    "webpack": "5.57.1",
    "webpack-cli": "4.9.0",
    "format-util": "1.0.5",
    "source-map-loader": "3.0.0",
    "css-loader": "6.3.0",
    "style-loader": "3.3.0",
    "webpack-dev-server": "4.3.1"
  },
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
The file 
kotlin/42bieres-shared-js.js
  do exists.
b
Set version in gradle buildscript
Alternatively see if npm-publish helps
s
Which gradle script? The one at the root? It's probably not at the module level because that is currently set and not here. And is npm-publish can publish locally? I don't want to have my project made public Thanks!
b
build.gradle.kts for each kotlin.js module
you can use npm-publish pack task to assemble npm tarball which you can install. Have a look at how sandbox/ts-consumer is setup on the repo.
a
in
build.gradle.kts
just go like
Copy code
version = "0.0.12"
Or if the versions of the whole submodules are the same, got to the root level
build.gradle.kts
and type
Copy code
allProjects {
  version = "0.0.12"
}
b
FYI: you can set the default version globally by adding version property to gradle.properties
Then you can override it via buildscript or -Pversion=x.x.x cmdline option
s
I did set the version property to the root
build.gradle.kts
file and I did fix this issue. Thanks! Now… I’ll try npm-publish if I can fix my other issue… 🙃