Error [ERR_MODULE_NOT_FOUND]: Cannot find package
Node.js could not resolve an imported package or file from the current project and module system.
What does this error mean?
The Node.js module loader followed an `import` statement and could not map its package name or file path to an installed, exported, and readable module.
Why does this happen?
- The dependency is missing from node_modules or package.json.
- The import contains the wrong package name, path, letter casing, or file extension.
- Dependencies were installed in another workspace or directory.
- The package exports map does not expose the imported subpath.
- CommonJS and ES module configuration are being mixed incorrectly.
AI explanation
Node resolves package imports from the current project boundary and local dependency tree. For a bare package name, verify installation and workspace location. For a relative import, verify the exact path, casing, extension, and module format. The URL shown in the error identifies the resolution point that failed.
Quick fix
npm install npm ls --depth=0 node -p "process.version"
Step-by-step fix
npm install <package> npm ls <package>
npm ci npm run build
Alternative solutions
npm
npm install npm ls <package>
Use npm when package-lock.json is the committed lockfile.
pnpm
pnpm install pnpm why <package>
Run from the workspace root when pnpm-workspace.yaml is present.
Yarn
yarn install yarn why <package>
Keep the Yarn version aligned with the repository configuration.
ES modules
node --input-type=module -e "import('./src/index.js')"Relative ESM imports commonly require explicit file extensions.
Real example
import { createServer } from "./server";
createServer();import { createServer } from "./server.js";
createServer();Frequently asked questions
node_modules may be missing, the install may have failed, or the process may be running from a different workspace than the package.json you inspected.