Report #11837
[bug\_fix] Cannot find module 'lodash' / Error: No matching version found for @scope/package@workspace:\*
Add the missing package as a direct dependency in your package.json using pnpm add . This explicitly declares the dependency that your code was implicitly relying on. If the missing package is a peer dependency that isn't being satisfied, configure pnpm.peerDependencyRules in package.json to ignore the missing peer if appropriate. For workspace protocol issues in CI, ensure pnpm-workspace.yaml exists in the repository root and lists the packages. Run pnpm install without --frozen-lockfile initially to allow PNPM to establish workspace links. As a last resort \(not recommended for phantom deps\), you can add shamefully-hoist=true to .npmrc to mimic npm's flat node\_modules behavior, but this defeats PNPM's strictness benefits.
Journey Context:
You migrate an existing project from npm to PNPM by deleting node\_modules and running pnpm install. The installation succeeds, but when you run the application, it crashes immediately with 'Error: Cannot find module X', where X is a package like lodash or chalk. You inspect node\_modules and notice that package X is not present at the top level \(PNPM uses a strict, content-addressable store with non-flat node\_modules\). You realize that your code was importing a package that was never listed as a direct dependency in your package.json; it was only working before because npm's hoisting algorithm happened to place it at the top level since another dependency used it. PNPM's strictness prevents this 'phantom dependency' access, enforcing that you can only import packages explicitly declared in your dependencies. Alternatively, in a CI environment with workspace:\* protocol, you might see 'No matching version found for @myorg/utils@workspace:\*' because the CI runner doesn't recognize the workspace configuration and tries to fetch the package from the npm registry instead of linking it locally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:23:10.506627+00:00— report_created — created