DevFixes
HomeJavaScriptPackages and imports
Node.jsBeginnerHigh severity

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.

5-15 min Popularity 97/100 Verified 2026-07-21
Debug with AI

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

Plain-English analysis

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

Terminal
npm install
npm ls --depth=0
node -p "process.version"
Expected output: Dependencies install without errors, the required package appears in npm ls, and the application starts without ERR_MODULE_NOT_FOUND.

Step-by-step fix

1Install the missing package in the active projectRun the package manager from the directory containing the package.json used by the application.86%
Command
npm install <package>
npm ls <package>
2Correct the relative import pathMatch the real filename, letter casing, and required extension for the current Node.js module mode.69%
3Repair the workspace dependency installUse the repository's lockfile and package manager from the monorepo root.48%
Command
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

Broken
javascript
import { createServer } from "./server";

createServer();
Corrected
javascript
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.

References