Skip to content

fix(exec): don't inherit global config when installing to the npx cache - #10042

Open
Sanjays2402 wants to merge 1 commit into
npm:latestfrom
Sanjays2402:fix/issue-9890
Open

Sanjays2402 wants to merge 1 commit into
npm:latestfrom
Sanjays2402:fix/issue-9890

Conversation

@Sanjays2402

Copy link
Copy Markdown

Summary

When npx runs inside a global install's lifecycle script, npm_config_global=true leaks into its environment. That flag reached the Arborist instance used for the npx cache install, so arborist linked bins to the global-style <npxCache>/bin target while exec() looked for them in <cacheDir>/node_modules/.bin. The result was sh: <bin>: command not found (and, on newer trees, a broken cache entry with no package.json).

The npx cache is never a global install, so this forces global: false on the npx cache Arborist, matching the approach the issue's root-cause analysis suggested.

Fixes: #9890

Changes

  • workspaces/libnpmexec/lib/index.js - force global: false on the npx cache Arborist so bins link under the cache dir's node_modules/.bin
  • workspaces/libnpmexec/test/registry.js - regression test running exec with global: true against the mock registry, asserting the bin runs, no <npxCache>/bin is created, and bins land in the cache dir's node_modules/.bin

Verification

  • Reproduced the broken behavior end-to-end before the fix (npm_config_global=true npm exec --yes cowsay hello failed; bins landed in _npx/bin/, no package.json written to the cache dir). After the fix the same command prints the cowsay output and bins land in <hash>/node_modules/.bin.
  • New regression test fails on unfixed code (PackageJson.load ENOENT from the broken cache entry) and passes with the fix.
  • Full libnpmexec suite: 9/9 suites, 119 assertions, all passing. ESLint clean on both touched files.

Fixes: npm#9890

When npx runs inside a global install's lifecycle script, npm_config_global=true leaks into its environment. That flag reached the Arborist instance used for the npx cache, so arborist linked bins to the global-style <npxCache>/bin target while exec() looked for them in <cacheDir>/node_modules/.bin, and the command failed with 'command not found'. The npx cache is never a global install, so force global:false on its Arborist.
@Sanjays2402
Sanjays2402 requested a review from a team as a code owner September 25, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npm exec (npx) links bins to the wrong directory when run from a global install's lifecycle script, causing "command not found" and install rollback

1 participant