Skip to content

[BUG] devDependencies of project with npm-shrinkwrap.json are getting installed #4323

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

Open
2 tasks done
RandomByte opened this issue Jan 25, 2022 · 13 comments
Open
2 tasks done
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@RandomByte
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When installing a package (npm install <package name>) from the npm registry that contains an npm-shrinkwrap.json, dependencies listed with "dev": true are installed unexpectedly.

Expected Behavior

devDependencies of the published package should not be installed when consuming the package.

Steps To Reproduce

Given: Node.js v16.13.2 and npm v8.3.2

I created an example project to showcase this issue: https://github.com/RandomByte/npm-shrinkwrap-test

  1. git clone git@github.com:RandomByte/npm-shrinkwrap-test.git && cd npm-shrinkwrap-test
  2. npm install
  3. Check for known devDependency "ava" and notice that it has been installed:
    npm ls -a | grep 'ava'
    > ├─┬ ava@3.15.0 extraneous
    
  4. npm prune --production removes the ava package. But a following npm install will install it again

It seems that after installing @ui5/cli@next in the empty project, its devDependencies where installed as normal dependencies. This is unexpected since a consumer of the package does not need its devDependencies.

In the past (with npm v6) we worked around this issue by executing npm prune --production followed by npm shrinkwrap during publishing of the @ui5/cli package. This basically removed all devDependencies from the npm-shrinkwrap.json (see SAP/ui5-tooling#283 (comment)). But this does not seem to work with npm v8 anymore, as the npm-shrinkwrap.json is not being updated after the prune took place.

I think the fundamental issue is present since at least npm v6. Relevant issues are:

Environment

  • npm: v8.3.2
  • Node.js: v16.13.2
  • OS Name: macOS 12.1 (Monterey)
  • System Model Name: MacBook Pro
  • npm config:
registry = "https://registry.npmjs.com/" 
@RandomByte RandomByte added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jan 25, 2022
@bkendall
Copy link

I'm going to +1 this via comment as well for visibility: I just worked around this in part of our build process for firebase-tools; it caused our prebuilt binaries to bloat from 130MB to 800MB+ and had to work pretty hard to find a workaround (thankfully we found one).

@nlf nlf added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Mar 8, 2022
@nlf
Copy link
Contributor

nlf commented Mar 8, 2022

confirmed bug, we're ignoring the dev flag in the npm-shrinkwrap.json, installing the dev dependencies and flagging them as extraneous when we write the package-lock.json.

i confirmed the npm-shrinkwrap.json flags the relevant deps as dev.

as noted, npm prune --production removes the extraneous deps from node_modules but not from the package-lock, so a follow up npm install puts them right back.

as a further note, npm install --only=prod does skip reifying the dev deps, as does npm install --omit=dev so we are internally identifying them correctly, just for some reason when we reify a dep with a shrinkwrap we're not applying the default rules for dev dependencies.

@bkendall
Copy link

@nlf any chance that this can get prioritized?

Another interesting issue that comes with this is that npm audit (which probably shouldn't be running when a module is installed globally in our case, but that's another bug) checks all the dev dependencies that were installed too, which creates more noise for end users of our shrinkwrap'd CLI.

@haines
Copy link

haines commented Apr 27, 2022

It's also quite frustrating with Dependabot updates, because Dependabot uses npm install --package-lock-only which does not result in the shrinkwrapped devDependencies being installed. This creates churn with Dependabot removing the extraneous package-lock.json entries and then local npm install reintroducing them.

@bkendall
Copy link

bkendall commented Apr 27, 2022

This is something that we're scratching our head to solve. Installing all our dev dependencies when installing firebase-tools globally takes up a ton of space, and it'd be nice to not do that. We've come across other options like clean-publish but working around this issue in npm seems like not the correct way to do it long term.

It'd be really appreciated if this could be addressed soon! Thanks!

@bkendall
Copy link

Another week, another person surprised when dev dependencies are installed and it triggers other audit warnings too. It would be really great to get this fixed.

firebase/firebase-tools#4586

@bkendall
Copy link

bkendall commented Jun 7, 2022

Once again, another person has escalated an issue to me where the dev dependencies are being installed. Would love to see this addressed soon.

@cupidchan
Copy link

Is there any timeline for this issue? It's pretty confusing to see so many irrelevant errors/warnings.

@antonstefer
Copy link

Commenting for visibility. Not sure if you're responsible @nlf but this deserves some attention.

@cupidchan
Copy link

This issue has been opened for a while now and we still see those irrelevant warnings and errors. Can this be prioritized and fixed in the near future? Thanks!

@bkendall
Copy link

I've given up on this ever being fixed and worked around it using clean-publish. I'd like to get back to using npm directly, but cutting the installed size by 75% just cannot be a benefit that I can wait on any longer.

lfdebrux added a commit to alphagov/govuk-prototype-kit that referenced this issue Nov 23, 2022
Fixes issue #1799.

We use npm shrinkwrap to try and improve security for users, however the
shrinkwrap file includes dev dependencies, and a bug in npm [[1]] means
that users are getting the dev dependencies whenever they create a new
prototype.

This commit changes the publishing process so that these dev
dependencies are removed from package.json and npm-shrinkwrap.json,
using the tool [clean-publish].

[1]: npm/cli#4323

[clean-publish]: https://github.com/shashkovdanil/clean-publish#readme
@RandomByte
Copy link
Author

Update: This can still be reproduced as described with Node v20.11.1 and npm v10.2.4

@marcbachmann
Copy link

We've also just noticed that with the most recent versions of node (22.11 & 23.2) and npm (10.9.0).
This is my current workaround to generate a npm-shrinkwrap.json without devDependencies:

node -e 'const pkg = require("./package.json"); delete pkg.devDependencies; fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2))'
npm prune --omit=dev
npm shrinkwrap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

7 participants