[BUG] `bundledDependencies` does not bundle relevant executables
Current Behavior:
Bundled dependencies do not export executables when packing.
Expected Behavior:
npm pack output should include scripts under .bin to launch any executables provided by the bundled depdency.
Steps To Reproduce:
- Install any dependency that exposes an executable, e.g.
lws. - Include this dependency in
bundledDependencies npm pack- The resulting artifact includes the
bundledDependencyundernode_modules, but does not create a.bindirectory at all, and so the depdency's executable(s) will not be available.
Environment:
- WIn10 20H2
- Node: 14.15.4
- npm: 6.14.10
Notes
I see from https://github.com/npm/cli/issues/1689 that bundledDependencies does not currently do special handling of the dep's package.json, such as looking at the files field. It's probably impractical / undesirable to process the whole bin field from package.json during pack, but at least it would make sense to check the existing node_modules/.bin for scripts that exactly match the package name and include those in the output.
What happens with npm v7.4.0?
I tested it just now and the behavior is the same. The node_modules directory does not have a .bin at all.
For a simpler repro, try a package file like
"dependencies": {
"rimraf": "^3.0.2",
},
"bundleDependencies": [
"rimraf",
}
npm install will create node_modules/.bin/rimraf, plus rimraf.cmd and rimraf.ps1 (at least on WIndows), but npm pack won't include them.
Having the same problem trying to run ts-node after unpacking my app from the result of npm pack with appropriate bundledDependencies. The ts-node module is included under node_modules, yarn start expects the .bin to be in place, but no .bin directory is found under node_modules.
In the short term I've rewritten some of my scripts to use the deep path into node_modules, e.g. "start": "node ./node_modules/ts-node/dist/bin.js src/main.ts", but it's bad ergonomics at least.
@thw0rted npm install should link any binaries your bundled deps have. If you're not seeing that happen, try running npm rebuild.
Do you mean to make an artifact with npm pack, then extract the TGZ, then run npm install inside the unpacked directory? I expect that would work, but it defeats the purpose of bundledDependencies -- I'm trying to make a package that can be run standalone, without connection to an NPM repo. Wouldn't npm install fail in such a scenario, before it makes links?
npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.
If your bug is preproducible on v7, please re-file this issue using our new issue template.
If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo
I'm still getting this, I'm trying to bundle everything so it doesn't need to be installed on deployment but when using npm pack it misses node_modules/.bin folder, are there any updates?