-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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] Updating a dependency in a workspace with overrides
duplicates the package
#6979
Comments
Additional info:
|
Cannot reproduce with the steps given. I suspect what's happening here is that the old version is valid for some other dependency in the tree, but the new version isn't, so the new version won't hoist. ~/D/n/s/a $ npm init -y; npm init -y -w workspace-a
~/D/n/s/a $ npm i [email protected] -w workspace-a
~/D/n/s/a $ npm i [email protected] -w workspace-a
~/D/n/s/a $ npm ls
[email protected] /Users/wraithgar/Development/npm/scratch/a
└─┬ [email protected] -> ./workspace-a
└── [email protected]
~/D/n/s/a $ ls node_modules/
abbrev/ workspace-a@
~/D/n/s/a $ ls node_modules/workspace-a/
package.json |
Ah. It seems the bug is more subtle than I first thought. It only happens if the root Here is a script that reproduces the issue:
Note that the |
overrides
duplicates the package
To be clear, the above script will "unhoist" abbrev (move it down into the package), but it will not duplicate it. If you also run ExamplesUpdate abbrev in-place (standalone)Script:npm init -y
npm init -y -w workspace-a
npm i --save-exact [email protected] -w workspace-a
npm i --save-exact [email protected] -w workspace-a Result:{
"name": "npm-repro",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-repro",
"version": "1.0.0",
"license": "ISC",
"workspaces": [
"workspace-a"
]
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"node_modules/workspace-a": {
"resolved": "workspace-a",
"link": true
},
"workspace-a": {
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"abbrev": "1.1.1"
}
}
}
} Update abbrev in-place (external dependency)Script:npm init -y
npm init -y -w workspace-a
npm i --save-exact [email protected] -w workspace-a
# [email protected] depends on abbrev@^1.0.0
npm i --save-exact [email protected] -w workspace-a
npm i --save-exact [email protected] -w workspace-a Result:{
"name": "npm-repro",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-repro",
"version": "1.0.0",
"license": "ISC",
"workspaces": [
"workspace-a"
]
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"node_modules/nopt": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz",
"integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==",
"dependencies": {
"abbrev": "^1.0.0"
},
"bin": {
"nopt": "bin/nopt.js"
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/workspace-a": {
"resolved": "workspace-a",
"link": true
},
"workspace-a": {
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"abbrev": "1.1.1",
"nopt": "6.0.0"
}
}
}
} Move abbrev into packageScript:npm init -y
npm init -y -w workspace-a
# Add an "overrides" section to the root package.json
pkg=$(jq '.overrides |= {"ava": "5.3.1"}' package.json)
echo "$pkg" > package.json
npm i --save-exact [email protected] -w workspace-a
npm i --save-exact [email protected] -w workspace-a Result:{
"name": "npm-repro",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-repro",
"version": "1.0.0",
"license": "ISC",
"workspaces": [
"workspace-a"
]
},
"node_modules/workspace-a": {
"resolved": "workspace-a",
"link": true
},
"workspace-a": {
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"abbrev": "1.1.1"
}
},
"workspace-a/node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
}
}
} Duplicate abbrevScript:npm init -y
npm init -y -w workspace-a
# Add an "overrides" section to the root package.json
pkg=$(jq '.overrides |= {"ava": "5.3.1"}' package.json)
echo "$pkg" > package.json
npm i --save-exact [email protected] -w workspace-a
npm i --save-exact [email protected] -w workspace-a
npm i --save-exact [email protected] -w workspace-a Result:{
"name": "npm-repro",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-repro",
"version": "1.0.0",
"license": "ISC",
"workspaces": [
"workspace-a"
]
},
"node_modules/abbrev": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.0.tgz",
"integrity": "sha512-c92Vmq5hfBgXyoUaHqF8P5+7THGjvxAlB64tm3PiFSAcDww34ndmrlSOd3AUaBZoutDwX0dHz9nUUFoD1jEw0Q=="
},
"node_modules/nopt": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz",
"integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==",
"dependencies": {
"abbrev": "^1.0.0"
},
"bin": {
"nopt": "bin/nopt.js"
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/workspace-a": {
"resolved": "workspace-a",
"link": true
},
"workspace-a": {
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"abbrev": "1.1.1",
"nopt": "6.0.0"
}
},
"workspace-a/node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
}
}
} Note: These scripts use the jq cli tool for some minor json editing, but those steps can be done by hand. |
I still think this isn't a bug, just an inefficiency. The tree is still valid, and if you run This is in the grey area of npm not trying to calculate the most efficient tree on every operation. There is no need, and it is ultimately an impossible task in some cases. It builds a correct tree. The fact that the presence of |
I still think this is a bug. It's not uncommon for large applications to need to reach into dependencies of dependencies, and when there are multiple versions of that subdependency installed things can go weird; |
The only way to guarantee one version of a dep is if everything that needs it declares it as a peer dependency - thus, react, babel, webpack, eslint, etc, because it's only when identity matters that you'd need to ensure one copy of a dep. What dep do you need unduplicated but that isn't commonly declared as a peer dep? |
I filed this issue after running into a problem with having multiple versions of the |
in that case, that's a bug in either |
Confirmed that this is fixed in 11.2.0 |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Updating a dependency should update the installed package in-place, not cause duplication.
Expected Behavior
The package is duplicated, and the old version is still present.
Steps To Reproduce
foo
)foo
, and runnpm install
<root>/node_modules/<package>
npm install
, runningnpm install <package>@version
from insidefoo
, or runningnpm install <package>@version -w
<path/to/>foo`At this point the new version of the dependency will be installed to
<root>/<path/to/>foo/node_modules/<package>
, and the old version will still be present at<root>/node_modules/<package>
.Environment
The text was updated successfully, but these errors were encountered: