Closed
Labels
Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release
Description
Is there an existing issue for this?
- I have searched the existing issues
[BUG] npm install removes linked packages, npm link replaces linked package contents #2380 seems similar but is a 7.x bug and predates the--install-linksoption.
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
Installing a package with --install-links false, deleting node_modules, then running npm install reinstalls the module as a link and updates package-lock.json
Expected Behavior
npm install should honor and not change package-lock.json, the package should be copied, not linked
Steps To Reproduce
- git clone https://github.com/oshi97/install-links.git
- cd parent
- npm i --no-install-links ../child
- ls -l node_modules
- cat package-lock.json
- rm -Recurse -Force node_modules
- npm install
- ls -l node_modules
- cat package-lock.json
At step 4: d---- 2022-12-14 12:21 PM child
At step 5:
"node_modules/child": {
"version": "1.0.0",
"resolved": "file:../child",
"license": "ISC"
}
},
"dependencies": {
"child": {
"version": "1.0.0"
}
}
At step 8: l---- 2022-12-14 12:23 PM child -> <REPO>\child\
At step 9:
"node_modules/child": {
"resolved": "../child",
"link": true
}
},
"dependencies": {
"child": {
"version": "file:../child"
}
}
Environment
- npm: 8.19.2
- Node.js: 18.12.1
- OS Name: Windows 11
- npm config:
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.12.1
; npm local prefix = <REPO>\parent
; npm version = 8.19.2
; cwd = <REPO>\parent
; HOME = <HOME>Reacted by Maximilian Roos, Alexis THOMAS, Tolstikov Vladimir and Manu Artero Anguita
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release
Activity
fardolieri commentedon Dec 15, 2022
I have a similar problem in npm 9, where I explicitly use
npm linkto create a symlink to my package. But after runningnpm install, the symlink disappears and my package is installed again becauseinstall-linksdefaults to true since npm 9. I think it would be great if the config was somehow reflected in the package.json.Maybe something like this:
Sabiil commentedon Dec 16, 2022
After updating npm from 8 to 9.2.0 version I can't install local packages with symlinks.
E.g. I have a local package "react-ui" with some React components.
When I run command "npm i ../../_packages/react-ui" in other project, I used to have
section in package.json and this section
in package-lock.json.
Files of "react-ui" package weren't copied to the "node_modules" folder of another project. It was very handy, because I don't have to run update every time I change "react-ui" package.
But now command "npm i ../../_packages/react-ui" copies all files to the "node_modules" folder of the project.
manuartero commentedon Feb 16, 2023
@fardolieri :
But according to [npm docs](the symlink disappears and my package is installed again because install-links defaults to true since npm 9) the default value is
false, is this a 'issue' in the documentation itself?mlemoine-clgx commentedon Feb 16, 2023
@manuartero
The default value of
--install-linksshould be used when installing a new package.When reinstalling packages based on the
package-lock.json(npm installwithout a package name), I think npm should follow whatever value was specified when the package was installed.(I agree that @fardolieri's problem might be a different issue from the original bug)
fardolieri commentedon Feb 16, 2023
It looks like it was changed back last week #6142. That probably fixes my issue. I'll try it out next week and I hopefully don't forget to give you guys an update.
fritzy commentedon Mar 1, 2023
As you said, we reverted this recently. Please re-open this issue if it is still a problem.
mlemoine-clgx commentedon Mar 1, 2023
@fritzy
This revert did not fix the issue:
Please note that for npm to install the package as a copy and not a link, we need to specify
--no-install-links falsewhich is very unintuitive and probably a bug as well!I expect the latest
npm ito reinstall the package exactly the way it was originally installed.tallero commentedon Mar 4, 2025
I'd like to report that as of today with npm version 11 if I do run
npm keeps installing a link instead than copying the directories over.
I have no idea I should be supposed to actually install the packages instead of creating links, except than directly copying the packages into the
node_modulesdirectory.