ERR_MODULE_NOT_FOUND node module_error ai_generated true

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

ID: node/err-module-not-found

Also available as: JSON · Markdown
87%Fix Rate
89%Confidence
340Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Node.js cannot resolve the specified module. Common with ESM/CJS conflicts or missing dependencies.

generic

Workarounds

  1. 92% success Run npm install to ensure all dependencies are installed
    rm -rf node_modules && npm install

    Sources: https://docs.npmjs.com/cli/v10/commands/npm-install

  2. 85% success Check package.json exports field matches the import path
    Check package.json exports field matches the import path

    Sources: https://nodejs.org/api/packages.html#package-entry-points

Dead Ends

Common approaches that don't work:

  1. Add .js extension to import 60% fail

    Only works for local files, not for node_modules

  2. Switch type in package.json between module and commonjs 68% fail

    May break other imports throughout the project

Error Chain

Leads to:
Preceded by:
Frequently confused with: