Part of #9608.
Is there an existing issue for this?
This issue exists in the latest npm version
This is not just a request to bump a dependency for a CVE
Current Behavior
Switching the install strategy in the same project directory leaves stale state in both directions. Switching hoisted → linked leaves the previous strategy's real top-level transitive directories (e.g. balanced-match, brace-expansion, concat-map) on disk alongside the new .store/ and symlinks. Switching linked → hoisted leaves the entire node_modules/.store/ directory behind. A fresh install of either strategy produces a clean layout.
Expected Behavior
Switching strategy should remove the layout artifacts of the previous strategy: stale top-level real directories should be cleaned up when entering the linked strategy, and .store/ should be removed when leaving it.
Steps To Reproduce
cd "$(mktemp -d)"
echo '{ "name": "sw", "version": "1.0.0", "dependencies": { "minimatch": "3.0.4" } }' > package.json
echo 'install-strategy=hoisted' > .npmrc
npm install >/dev/null # real dirs: balanced-match, brace-expansion, concat-map, minimatch
echo 'install-strategy=linked' > .npmrc
npm install >/dev/null
ls -l node_modules | grep -E 'balanced-match|brace-expansion|concat-map' # still real dirs (stale)
# a fresh linked install has only `minimatch` (symlink) + .store/
# reverse direction:
echo 'install-strategy=hoisted' > .npmrc
npm install >/dev/null
ls node_modules/.store # still present (stale); a fresh hoisted install has no .store
Environment
- npm: 12.0.0-pre.1 (
latest)
- Node.js: v24.17.0
- OS Name: macOS (Darwin 25.5.0)
- System Model Name: MacBook (arm64)
- npm config:
Part of #9608.
Is there an existing issue for this?
This issue exists in the latest npm version
This is not just a request to bump a dependency for a CVE
Current Behavior
Switching the install strategy in the same project directory leaves stale state in both directions. Switching hoisted → linked leaves the previous strategy's real top-level transitive directories (e.g.
balanced-match,brace-expansion,concat-map) on disk alongside the new.store/and symlinks. Switching linked → hoisted leaves the entirenode_modules/.store/directory behind. A fresh install of either strategy produces a clean layout.Expected Behavior
Switching strategy should remove the layout artifacts of the previous strategy: stale top-level real directories should be cleaned up when entering the linked strategy, and
.store/should be removed when leaving it.Steps To Reproduce
Environment
latest)install-strategy=linked