Where should I be looking for the `package.json` f...
# javascript
a
Where should I be looking for the
package.json
file for a project with
binaries.executable()
? i’ve looked at the file in
myproject/build/tmp/jsPublicPackageJson
and the one in
build/js/packages/myproject
and they are both missing packages from the dependency section that the generated js file has as
require.
If i go and look at the projects that pull in these dependencies directly their
package.json
files look as i would expect them to. This seems essentially the same as https://youtrack.jetbrains.com/issue/KT-45789
b
You want binaries.library() for that
a
so now I have a
myproject/build/productionLibrary/
but the package.json file has not changed its still missing the transitive dependencies
b
Do you even have any npm dependencies?
As in implementation(npm("module", "version"))
a
yes but they are not referenced directly. The js file has
Copy code
}(module.exports, require('@aws-sdk/config-resolver'), require('@aws-sdk/client-cognito-identity-provider'), require('@aws-sdk/client-kms'), require('@js-joda/core')));
but the package.json is
Copy code
{
  "name": "myproject",
  "version": "0.0.1",
  "main": "myproject.js",
  "types": "myproject.d.ts",
  "devDependencies": {},
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
all of those
require
are coming transitively from kotlin dependencies. So in my project I have
implementation("dep1:2.0.0")
but if we look at
build/js/packages_imported/dep1/2.0.0/package.json
it has the correct dependency
Copy code
{
  "name": "dep1",
  "version": "2.0.0",
  "main": "dep1.js",
  "types": "dep1.d.ts",
  "devDependencies": {},
  "dependencies": {
    "@aws-sdk/client-cognito-identity-provider": "3.34.0"
  },
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
b
Hmm, did you try using that executable at all? Kjs compiler might be embedding them into a final js output.
Alternatively, you can try npm-publish plugin
a
the executable works because i currently ship a
node_modules
with all the project dependencies in it
Hmm, did you try using that executable at all? Kjs compiler might be embedding them into a final js output.
So the compiler can put multiple modules in the same file?
b
Yes, it's already embedding all kjs (.klib) libs in the output
a
I think this is maybe down to confusion about how the binaries work and how I expect them to work.
if i run
./gradlew build
then do
node app.js
it works fine
but thats only executable assuming i run things in situ
if i take my ‘executable’ js file and run it somewhere else say the project root and change the
require
in my app.js file to match that new file location it breaks because the dependency is missing
I added a comment to that bug I think it warrants more discussion/documentation around what/how this is supposed to work
s
@Alex Edwards I'm facing exact same issue. I actually want to embed the resulting javascript library file via`script` tag in html. So without using
requireJs
. Please share more of your findings here regarding what's possible and what's not when including
npm
dependency on
kotlin/js
side
b
If you use binaries.executable() produced js file is self sufficient and bundled via webpack already
a
ca you expand on that? Where should i find this ‘self sufficient’ js file? I’m willing to believe i’m looking in the wrong place but so far i’ve not found anything thats self contained
b
Should be in build/distribution
Along with stuff from your src/jsMain/resources
a
at this moment, the generated package.json, doesn't include dependencies. Even with the npm-publish plugin. I have had this issue for a while and the hack was to add dependencies directly in the dependencies block of the npm-publish publications block
b
Bit late, but hopefully we can close this soon and fix it in KGP as opposed to npm-publish.
😍 1