Lingua-e
JavaScript

What is a ERR_MODULE_NOT_FOUND?

← Errors

ERR_MODULE_NOT_FOUND is thrown by Node.js when it cannot locate a module specified in an import or require() statement. It is the Node.js module-resolution error and covers both missing npm packages and missing local files.

Why it happens

  • The package is not installed (missing from node_modules), often because npm install was not run after cloning.
  • A relative import path points to a file that does not exist or uses the wrong path.
  • In ESM mode, the file extension is omitted from a relative import (Node.js ESM requires explicit extensions).
  • A package name was renamed or the entry point changed in a major version upgrade.

Examples

JavaScript

Code that triggers the error

// package.json has "type": "module"
import { helper } from "./utils/helper.js";

helper();

Error output

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

How to fix it

Run npm install to ensure all dependencies are present. Verify the exact file path and extension for local imports. In ESM projects, always include the .js extension (even when writing TypeScript, the compiled output is .js). Check the package's changelog if you recently upgraded a dependency.

Fixed code

// Ensure the file exists at the exact path, including extension
// For ESM imports, the .js extension is required even for TypeScript source
import { helper } from "./utils/helper.js";

helper();

// If using CommonJS:
// const { helper } = require("./utils/helper");

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free