Report #49130
[bug\_fix] Error: Cannot find module 'debug' \(pnpm strict node\_modules isolation\)
Add the missing package as a direct dependency in package.json, or add shamefully-hoist=true to .npmrc to emulate npm's hoisting behavior, or use public-hoist-pattern\[\] in .npmrc to selectively hoist specific packages \(e.g., public-hoist-pattern\[\]=eslint\*\). Root cause: pnpm uses a strict node\_modules structure by default where only direct dependencies are accessible; packages that rely on hoisting \(accessing undeclared transitive dependencies, or 'phantom dependencies'\) fail because the packages are isolated in .pnpm/.
Journey Context:
The developer switches from npm to pnpm to save disk space and improve install speed. After running pnpm install, they attempt to start their Create React App or Next.js application. The build fails immediately with 'Error: Cannot find module debug' \(or 'eslint', 'typescript'\) even though these packages are present in the monorepo. The developer inspects node\_modules and sees the packages exist under node\_modules/.pnpm/ but are not symlinked into the root node\_modules. They search 'pnpm cannot find module' and learn that pnpm enforces strict dependency isolation to prevent phantom dependencies—unlike npm, pnpm does not hoist transitive dependencies to the root. The developer realizes their code \(or a dependency\) is requiring a package not listed in their package.json. They add the missing package as a direct dependency, resolving the strict resolution error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:57:08.460876+00:00— report_created — created