Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] bundledDependencies does not bundle relevant executables #2491

Open
thw0rted opened this issue Jan 14, 2021 · 8 comments
Open

[BUG] bundledDependencies does not bundle relevant executables #2491

thw0rted opened this issue Jan 14, 2021 · 8 comments
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@thw0rted
Copy link

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 #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 thw0rted added Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release labels Jan 14, 2021
@ljharb
Copy link
Collaborator

ljharb commented Jan 14, 2021

What happens with npm v7.4.0?

@thw0rted
Copy link
Author

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.

@ljharb ljharb added the Release 7.x work is associated with a specific npm 7 release label Jan 14, 2021
@jeanlescure
Copy link

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.

@thw0rted
Copy link
Author

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.

@darcyclarke
Copy link
Contributor

darcyclarke commented Feb 2, 2021

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

@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label Feb 2, 2021
@thw0rted
Copy link
Author

thw0rted commented Feb 2, 2021

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?

@darcyclarke
Copy link
Contributor

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

@ljharb ljharb removed the Release 6.x work is associated with a specific npm 6 release label Jun 3, 2021
@ljharb ljharb reopened this Jun 3, 2021
@semics-tech
Copy link

semics-tech commented Jun 21, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
5 participants