[BUG] npm-shrinkwrap.json of a tarball is being ignored #5349
Labels
Bug
thing that needs fixing
Needs Triage
needs review for next steps
Release 8.x
work is associated with a specific npm 8 release
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When installing an NPM package that contains an npm-shrinkwrap.json, the npm-shrinkwrap seems to be ignored and the latest dependency that adheres to the package.json semver range is installed instead.
This may be related to #4583, but in this case, we're trying to install a tarball (e.g.,
https://mysite.com/path/here/package-name.tgz
).If we take a simple package.json:
Then, if we create an npm-shrinkwrap.json from this package (after npm install), it will explicitly list React at version 17.0.0 inside the npm-shrinkwrap.json (under packages and dependencies):
A consuming package will install React@17.0.0 perfectly fine, as the package.json has "17.0.0" explicitly listed.
However, if we update React's version in package.json to "^17.0.0" without updating npm-shrinkwrap.json, the consuming package will install 17.0.2 instead. I'm simplifying the behavior, but this issue is amplified when we have transitive dependencies.
Expected Behavior
The expected behavior is when installing an NPM package with an npm-shrinkwrap.json, the versions of dependencies listed in the npm-shrinkwrap.json are respected. In the given example, React should be installed React at 17.0.0 instead of 17.0.2.
Based on npm-shrinkwrap and package-lock.json vs npm-shrinkwrap.json, is that npm-shrinkwrap.json is publishable so consuming packages can install dependencies based on that shrinkwrap. The registry states "If this field is undefined, the client must determine through other means if a shrinkwrap exists.", but I do not see a way to do this.
Am I understanding shrinkwrap correctly or using anything wrong?
Steps To Reproduce
See the README in making3/npm-shrinkwrap-issue:
Using NPM v8+:
npm pack
.npm install /path/to/packed/npm-shrinkwrap-issue-1.0.0.tgz
.grep "version" node_modules/react/package.json
)Environment
The text was updated successfully, but these errors were encountered: