Skip to content

feat: explain why a dependency was installed on resolution errors#9581

Open
everett1992 wants to merge 1 commit into
npm:latestfrom
everett1992:explain-install-errors
Open

feat: explain why a dependency was installed on resolution errors#9581
everett1992 wants to merge 1 commit into
npm:latestfrom
everett1992:explain-install-errors

Conversation

@everett1992

@everett1992 everett1992 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Attach a structured dependency explanation (the same shape ERESOLVE errors carry) to install errors that target a specific dependency, and render it in the CLI using the npm explain format. This shows users which path pulled a package in, since removing that path is how they avoid the error - if it's not transient.

Covered errors:

  • ETARGET, EALLOWREMOTE/EALLOWGIT, tarball/network, EINCOMPLETEMANIFEST (resolution phase, via build-ideal-tree #failureNode/#pruneFailedOptional)
  • EALLOWREMOTE/EALLOWGIT, tarball/network, integrity (reify fetch phase, via #extractOrLink)
  • EBADENGINE, EBADPLATFORM (engine/platform checks)
  • ESTRICTALLOWSCRIPTS (install preflight uses the shared arborist helper so it carries explanations too)

New lib/utils/explain-dep-error.js formats the explanation (edge- or node-shaped) via the existing explain-dep formatters; error-message.js appends it and writes a full report file, mirroring explain-eresolve.

The explanation is computed lazily and best-effort via a shared attachExplanation(err, compute) helper: the graph walk only runs when a failure is actually fatal (optional/dropped load failures skip it), it never overwrites an existing explanation, and it never masks the original error. For ESTRICTALLOWSCRIPTS the explanation is omitted entirely if a node lacks explain().

npm explain requires a populated node_modules, so it can't help diagnose EALLOWREMOTE, ETARGET ect errors that prevent creation of node_modules. This includes a partial explanation along with the errors.

@everett1992 everett1992 requested review from a team as code owners June 19, 2026 00:33
Attach a structured dependency explanation (the same shape ERESOLVE
errors carry) to install errors that target a specific dependency, and
render it in the CLI using the `npm explain` format. This shows users
which path pulled a package in, since removing that path is how they
avoid the error.

Covered errors:
- ETARGET, EALLOWREMOTE/EALLOWGIT, tarball/network, EINCOMPLETEMANIFEST
  (resolution phase, via build-ideal-tree #failureNode/#pruneFailedOptional)
- EALLOWREMOTE/EALLOWGIT, tarball/network, integrity (reify fetch phase,
  via #extractOrLink)
- EBADENGINE, EBADPLATFORM (engine/platform checks)
- ESTRICTALLOWSCRIPTS (install preflight uses the shared arborist helper
  so it carries explanations too)

New lib/utils/explain-dep-error.js formats the explanation (edge- or
node-shaped) via the existing explain-dep formatters; error-message.js
appends it and writes a full report file, mirroring explain-eresolve.

The explanation is computed lazily and best-effort via a shared
attachExplanation(err, compute) helper: the graph walk only runs when a
failure is actually fatal (optional/dropped load failures skip it), it
never overwrites an existing explanation, and it never masks the
original error. For ESTRICTALLOWSCRIPTS the explanation is omitted
entirely if a node lacks explain(). Full 100% test coverage.
@everett1992 everett1992 force-pushed the explain-install-errors branch from 78c0b6a to 6134eb4 Compare June 19, 2026 01:46
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.

1 participant