---
title: "How do you fix \"Error: Cannot find module\" in Node.js?"
description: "Cannot find module means Node cannot resolve an import. Install dependencies, fix the relative path or extension, or check ESM versus CommonJS settings."
url: "https://bugsee.com/answers/nodejs/fix-cannot-find-module/"
---

# How do you fix "Error: Cannot find module" in Node.js?

Node could not resolve the path or package you required. Run `npm install`, check the spelling and relative path, and confirm the file exists with the right extension.

- Package import (`require("express")`): run `npm install`, and check that the package is listed in dependencies and that `node_modules` is not stale. Deleting `node_modules` and the lock file, then reinstalling, fixes corrupted installs.
- Relative import (`require("./utils")`): the path must be relative to the importing file, and the case must match on case-sensitive systems like Linux.
- ES modules: relative imports need the full extension (`import "./utils.js"`), and a `package.json` with `"type": "module"` changes how files are loaded.
- Wrong working directory: scripts started from another folder resolve packages from the file's location, not from where you ran the command, so check the entry point's path.
- Build output: if you run compiled code, make sure the build step produced the file and that you start the compiled entry, not the source.

The error message prints a Require stack listing each file in the import chain, so start from the first entry to see which file asked for the missing module.

## Related questions

- [What is the difference between npm and npx?](https://bugsee.com/answers/nodejs/difference-between-npm-and-npx/)
- [What is the difference between module.exports and export in Node.js?](https://bugsee.com/answers/nodejs/module-exports-vs-esm/)
