node module_error ai_generated true

Error: Cannot find module './X' (local file import)

ID: node/cannot-find-module-relative

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Local file import failed. Wrong path, missing extension, or file doesn't exist.

generic

Workarounds

  1. 95% success Check the file path — case-sensitive on Linux: ./Utils.js != ./utils.js
    ./Utils.js != ./utils.js

    Sources: https://nodejs.org/api/modules.html#file-modules

  2. 90% success For TypeScript/ESM, you may need the extension: import './file.js' (not .ts)
    import './file.js' (not .ts)

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

  3. 88% success Verify the file exists at the path relative to the importing file
    Verify the file exists at the path relative to the importing file

    Sources: https://nodejs.org/api/modules.html#file-modules

Dead Ends

Common approaches that don't work:

  1. Install it as an npm package 90% fail

    It's a local file (./), not a package — it won't be on npm

  2. Add an index.js file 65% fail

    Only works if importing a directory, not a specific file

Error Chain

Leads to:
Preceded by: