ERR_MODULE_NOT_FOUND node esm ai_generated true

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/utils' imported from /app/index.js

ID: node/err-module-not-found-esm

Also available as: JSON · Markdown
94%Fix Rate
96%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

ESM import cannot find the module — missing file extension in import path.

generic

Workarounds

  1. 96% success Add the .js file extension to imports: import { fn } from './utils.js'
    ESM requires explicit file extensions unlike CJS

    Sources: https://nodejs.org/api/esm.html#mandatory-file-extensions

  2. 85% success Configure TypeScript or bundler to handle extension rewriting
    In tsconfig: moduleResolution: 'nodenext' adds extensions in output

Dead Ends

Common approaches that don't work:

  1. Adding 'type': 'commonjs' to package.json 70% fail

    Switches the entire project back to CJS; breaks ES imports

  2. Using require() instead of import 65% fail

    Mixing module systems causes more problems

Error Chain

Frequently confused with: