cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] `bundledDependencies` does not bundle relevant executables

Open thw0rted opened this issue 4 years ago • 8 comments

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:

  1. Install any dependency that exposes an executable, e.g. lws.
  2. Include this dependency in bundledDependencies
  3. npm pack
  4. The resulting artifact includes the bundledDependency under node_modules, but does not create a .bin directory 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.

thw0rted avatar Jan 14 '21 13:01 thw0rted

What happens with npm v7.4.0?

ljharb avatar Jan 14 '21 15:01 ljharb

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.

thw0rted avatar Jan 14 '21 15:01 thw0rted

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.

jeanlescure avatar Jan 26 '21 02:01 jeanlescure

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 avatar Jan 26 '21 09:01 thw0rted

@thw0rted npm install should link any binaries your bundled deps have. If you're not seeing that happen, try running npm rebuild.

darcyclarke avatar Feb 02 '21 07:02 darcyclarke

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?

thw0rted avatar Feb 02 '21 08:02 thw0rted

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

darcyclarke avatar Jun 02 '21 21:06 darcyclarke

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?

semics-tech avatar Jun 21 '24 09:06 semics-tech