Skip to content

fix: prefer system npm/npx over project-local versions from node_modules#1172

Merged
mtorp merged 1 commit intov1.xfrom
fix/prefer-system-npx-over-project-local
Apr 7, 2026
Merged

fix: prefer system npm/npx over project-local versions from node_modules#1172
mtorp merged 1 commit intov1.xfrom
fix/prefer-system-npx-over-project-local

Conversation

@mtorp
Copy link
Copy Markdown
Contributor

@mtorp mtorp commented Apr 7, 2026

Summary

  • When the CLI runs inside an npm script (or any context where node_modules/.bin is on PATH), getNpxBinPath() could pick up a project-local npx instead of the system one
  • The standalone npx package (npx@10.2.2) bundles npm@5.1.0 which is incompatible with Node 22+, causing cb.apply is not a function errors during Coana reachability analysis
  • Fix: check for npm/npx next to process.execPath before falling back to PATH-based lookup, following the same pattern already used by findRealNpm() in @socketsecurity/registry and getAgentExecPath() in package-environment.mts

Test plan

  • TypeScript type check passes
  • Lint passes (0 errors)
  • All 871 unit tests pass (pre-commit hook)
  • Manual test: install npx@10.2.2 in a project, run scan with reachability from an npm script — should no longer crash

🤖 Generated with Claude Code


Note

Medium Risk
Medium risk because it changes how the CLI locates and executes npm/npx, which can affect behavior across environments (especially Windows and custom Node installs), though the change is narrowly scoped to path resolution.

Overview
Ensures the CLI prefers system npm/npx over project-local versions that may appear on PATH (e.g. from node_modules/.bin) by first probing for binaries next to process.execPath.

Adds findBinNextToNode() (with symlink resolution via resolveBinPathSync) and uses it in getNpmBinPathDetails()/getNpxBinPathDetails() before falling back to the existing PATH-based lookup, reducing failures from incompatible bundled npm/npx versions on newer Node runtimes.

Reviewed by Cursor Bugbot for commit 7a6441d. Configure here.

When the CLI runs inside an npm script (or any context where
node_modules/.bin is on PATH), getNpxBinPath() could pick up a
project-local npx instead of the system one. The standalone npx package
(npx@10.2.2) bundles npm@5.1.0 which is incompatible with Node 22+,
causing "cb.apply is not a function" errors during Coana reachability
analysis.

Fix: check for npm/npx next to process.execPath (the running node
binary) before falling back to PATH-based lookup. This follows the same
pattern already used by findRealNpm() in @socketsecurity/registry and
getAgentExecPath() in package-environment.mts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mtorp mtorp requested a review from jdalton April 7, 2026 13:01
@mtorp mtorp marked this pull request as ready for review April 7, 2026 13:01
@mtorp mtorp merged commit d322973 into v1.x Apr 7, 2026
13 checks passed
@mtorp mtorp deleted the fix/prefer-system-npx-over-project-local branch April 7, 2026 13:08
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.

2 participants