Report #20786
[bug\_fix] Error: Cannot find module '/path/to/module' or Error: Cannot find module 'node:path' \(in Node <14.18\)
Delete node\_modules and package-lock.json \(or yarn.lock/pnpm-lock.yaml\), ensure the correct Node.js version is active \(nvm use\), and reinstall. For 'node:' prefix errors, upgrade to Node.js 14.18.0\+ or remove the 'node:' prefix from imports.
Journey Context:
Developer switches git branches from a feature branch back to main, or upgrades Node.js version. They run npm start. Node.js crashes with 'Error: Cannot find module '../utils/helper'' even though the file exists on disk. The developer checks the path multiple times, clears require cache with no effect, and realizes that the node\_modules/.cache or the lockfile is stale from the previous branch or Node version, causing the module resolution algorithm to look in wrong paths or for binaries compiled for a different Node ABI. They also might encounter 'Error: Cannot find module node:path' because they are on Node 12 but the code uses the node: prefix \(introduced in 14.18\). The fix is to completely purge node\_modules and the lockfile, ensure the active Node version matches the project's .nvmrc \(nvm use\), and reinstall to regenerate a clean, consistent dependency tree and native binary bindings.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:17:35.483684+00:00— report_created — created