You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] npm install produces different results on first and second run #8535
A clean npm install produces different results on the first and second run.
Expected Behavior
npm install should produce the same results each time.
Steps To Reproduce
On mac, ignoring scripts just in case:
npm install -g npm@latest
mkdir test&&cdtest
npm init -y
npm install --ignore-scripts @abandonware/noble
# added 156 packages, and audited 157 packages in 972ms
npm install --ignore-scripts
# changed 12 packages, and audited 157 packages in 542ms
The second install shows "changed 12 packages" which is unexpected. This is also reproducible installing from package/lock files.
rm -rf node_modules
npm install --ignore-scripts
# added 156 packages, and audited 157 packages in 1s
npm install --ignore-scripts
# changed 12 packages, and audited 157 packages in 553ms
The different results are visible in the FS by diffing the output of find node_modules before and after.
Environment
npm: 11.5.2
Node.js: v22.14.0
OS Name: MacOS
System Model Name: Macbook Pro M4
npm config:
; node bin location = /Users/liam.mitchell/.local/share/fnm/node-versions/v22.14.0/installation/bin/node; node version = v22.14.0; npm local prefix = /Users/liam.mitchell/npm-install; npm version = 11.5.2; cwd = /Users/liam.mitchell/npm-install; HOME = /Users/liam.mitchell
Happens for us too. It even breaks our pipeline, because the second version that is generated will fail on npm ci with an package-lock out of sync error.
Happens for us too. It even breaks our pipeline, because the second version that is generated will fail on npm ci with an package-lock out of sync error.
@TillFProtzek I don't see a difference in package lock in my testing.
They are on the trash list because one optional dep failed (expected, unsupported platform) and optionalSet() determined that 144 other packages were related:
@liamcmitchell I had both occurences. Installs/deletions without any change to the package-lock, and some with changes to the package-lock. Regressed like you said to 11.2.0 and we have no problems anymore.
I have @swc/core as a dependency of one directly installed package (@swc-node/jest) and it has optional platform dependencies, which are installed on the clean npm install (no node-modules, no package-lock.json), but they are removed when running the npm install the second time. They are also removed when I run npm update --save.
#> npm install
...
added 1128 packages, and audited 1129 packages in 1m
...
#> npm install
...
added 1 package, removed 11 packages, and audited 1119 packages in 2s
...
This is 100% reproducible. I have the following dependencies in my packages.json:
This bug is super annoying. I had it happen for another transitive optional dependency of electron-builder- @electron/windows-sign
See #8563 (duplicate).
This is quite annoying, because the npm ci run during Docker build fails because of this dependency instability:
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm error
npm error Missing: @swc/helpers@0.5.15 from lock file
The npm install has to be run twice in order to npm ci succeed.
11.6.1 added #8579 which attempts to fix #8431 by incorrectly changing peer calc logic, causing unexpected package-lock changes and removals.
11.6.2 added #8537 which fixes optional set calc and #8602 which fixes inert-calc/trash/omit order. These fixes should have fixed my original issue but then I ran into #8431 and #8579.
11.6.3 added #8645 which reverts the problematic #8431 and #8579 and fixes the original issue by rewriting dep flag calc. This will cause unexpected package-lock changes and additions if package-lock was touched by 11.5.0-11.6.2. At this point I was happy that my npm install was reproducible and stopped investigating further.
11.10.1 added #8981 which fixes resolution of optional peer deps. Invalid optional peer deps will be ignored or corrected according save mode.
Use npm >= 11.10.1 to avoid the above issues!
Reacted by Philippe Serhal, Ulrich Stark, Matthew Costello and Serhii But
Reacted by Philippe Serhal, Adam Stachowicz, Stas Klymenko, Connor Bär, Daniel Schultz, Shunta KARASAWA and jiangfengri
Activity
liamcmitchell commentedon Aug 27, 2025
11.2 looks like it produces identical results between runs (expected behavior):
TillFProtzek commentedon Aug 27, 2025
Happens for us too. It even breaks our pipeline, because the second version that is generated will fail on
npm ciwith an package-lock out of sync error.liamcmitchell commentedon Aug 27, 2025
I've been trying to follow the code. From what I can see so far, the ideal tree looks the same in both runs.
Noticed that the 12 changed packages are marked because they are missing their
.bin/files:cli/workspaces/arborist/lib/diff.js
Line 127 in 75ce64a
So these files aren't created on first install?
alexsch01 commentedon Aug 27, 2025
@liamcmitchell I believe my issue #8409 is the reason for this difference on all platforms
liamcmitchell commentedon Aug 27, 2025
@TillFProtzek I don't see a difference in package lock in my testing.
liamcmitchell commentedon Aug 27, 2025
Those 12 bin flies are missing on first install because they were on the trash list:
cli/workspaces/arborist/lib/arborist/rebuild.js
Lines 381 to 383 in 3b54e9c
liamcmitchell commentedon Aug 27, 2025
They are on the trash list because one optional dep failed (expected, unsupported platform) and
optionalSet()determined that 144 other packages were related:cli/workspaces/arborist/lib/arborist/reify.js
Lines 830 to 838 in 3b54e9c
TillFProtzek commentedon Aug 28, 2025
@liamcmitchell I had both occurences. Installs/deletions without any change to the package-lock, and some with changes to the package-lock. Regressed like you said to 11.2.0 and we have no problems anymore.
liamcmitchell commentedon Aug 28, 2025
The 144 marked packages look valid, most of the deps are brought in by the unsupported platform dep.
Mermaid diagram shows marked packages in red, dotted lines show optional links.
It looks like there are a few deps that weren't marked and should have been. They are all optional dependencies themselves.
If I understand the graph correctly, I should only have 6 packages installed on my platform 🤔
oldium commentedon Sep 9, 2025
I think I just faced the same issue.
I have
@swc/coreas a dependency of one directly installed package (@swc-node/jest) and it has optional platform dependencies, which are installed on the cleannpm install(nonode-modules, nopackage-lock.json), but they are removed when running thenpm installthe second time. They are also removed when I runnpm update --save.This is 100% reproducible. I have the following dependencies in my
packages.json:oldium commentedon Sep 9, 2025
This is a minimal
package.jsoncase to see removed optional dependencies:This is a minimal
package.jsonto see alsonode_modules/@swc/helpersmoved undernode_modules/next/node_modules/@swc/helpers, because of the removal:fix: Optional dep's path cannot find in newest npm (#9274)
AviVahl commentedon Sep 14, 2025
This bug is super annoying. I had it happen for another transitive optional dependency of
electron-builder-@electron/windows-signSee #8563 (duplicate).
fix: calculate omit in diff (#8566)
oldium commentedon Sep 26, 2025
The results are better with npm 11.6.1 (optional dependency does not get removed), but the following example:
still gives unstable results for peer
@swc/helpers.oldium commentedon Sep 26, 2025
This is quite annoying, because the
npm cirun during Docker build fails because of this dependency instability:The
npm installhas to be run twice in order tonpm cisucceed.AviVahl commentedon Sep 27, 2025
the issue is mostly fixed for me after #8579 (included in npm@11.6.1)
@owlstronaut I still see a tiny 1 line difference that adds
"peer": trueon a secondnpm irun of https://github.com/AviVahl/example-electron-applicationSteps to reproduce:
fix: refactor node.ideallyInert to node.inert (#8602)
fix: dep flag calculation (npm#8645)
liamcmitchell commentedon Dec 8, 2025
Summary of recent npm install/package-lock issues:
savemode.Use npm >= 11.10.1 to avoid the above issues!
wraithgar commentedon Dec 8, 2025
Thank you @liamcmitchell I edited the issue to include your summary and a link to that comment, and am going to pin this issue for the time being.
Saibamen commentedon Feb 19, 2026
@liamcmitchell please update your comment about NPM version
11.10.1and #8981