Report #66441
[bug\_fix] Error: Cannot find module 'phantom-dep' after switching to pnpm
Add the missing package as a direct dependency in package.json \(npm install phantom-dep --save\), or configure pnpm to hoist dependencies using .npmrc with shamefully-hoist=true \(not recommended for long-term\).
Journey Context:
A developer switches a working project from npm to pnpm. Running the application immediately crashes with Error: Cannot find module 'is-odd' \(or similar\) at a require\('is-odd'\) call inside their code. The developer checks node\_modules and sees is-odd is not at the root, though it exists deep inside node\_modules/.pnpm. They realize that in npm, transitive dependencies are hoisted to the root, allowing code to accidentally require packages not listed in package.json \(phantom dependencies\). pnpm uses a strict node\_modules structure where only declared dependencies are accessible. The code worked by accident before. The fix works because adding the package to package.json declares the dependency explicitly, making it available in pnpm's strict structure and ensuring the code is robust against hoisting changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:59:52.848490+00:00— report_created — created