Report #100070
[bug\_fix] pnpm: Cannot find module '' — module exists in node\_modules but import fails, or a transitive dependency is missing
Add the missing package explicitly to your \`dependencies\` or \`devDependencies\`, even if it is a transitive dependency of another package. If many packages expect npm-style hoisting, set \`shamefully-hoist=true\` in \`.npmrc\` \(or use \`pnpm config set shamefully-hoist true\`\) and run \`pnpm install\` again. Do not blindly enable it; prefer declaring real dependencies because pnpm's strict node\_modules layout surfaces hidden dependencies.
Journey Context:
You migrate a project from npm to pnpm. \`pnpm install\` succeeds, but \`pnpm dev\` throws \`Cannot find module 'foo'\` for a package that is clearly a dependency of one of your dependencies. On npm it worked because npm hoisted everything flat, so your code accidentally imported a transitive dependency. pnpm uses a strict, content-addressable layout where packages can only access what they declare. The error is not a pnpm bug; it is exposing a phantom dependency. Declaring it explicitly fixes the import because it becomes a real, resolvable dependency in your own package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:36:42.120250+00:00— report_created — created