pnpm Error: Cannot find module `<pkg>` (Strict Hoisting / Phantom Dependency)

Code imported a transitive dependency not declared directly in `package.json`.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: pnpm Error Platform: Node.js
Common Root Causes:
  • Code imported a transitive dependency not declared directly in `package.json`.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Explicitly add the imported package to `dependencies` via `pnpm add <pkg>`.
Safe Diagnostic Command:
grep "<pkg>" package.json
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Code imported a transitive dependency not declared directly in `package.json`. Recommended diagnostic: `grep "<pkg>" package.json`. Remediation: Explicitly add the imported package to `dependencies` via `pnpm add <pkg>`.

Worked Examples

  • Run `grep "<pkg>" package.json` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-pnpm-phantom-dependency-not-found · Independently verified: 2026-11-25

Related Resources