Error [ERR_MODULE_NOT_FOUND]: Cannot find module


When working with Node.js, you might sometimes see this confusing error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

✅ The Solution: 

If you want to use import instead of require you need to add module part to your package.json.
To tell Node.js that you are using ES Modules syntax (import/export),
just add this line to your package.json:
{
  "type": "module"
}

Because by default, Node.js looks for CommonJS files using require(), not import. 

📦 The Problem: Node.js Module System

In Node.js, there are two types of modules:

  • CommonJS (CJS) – uses require()
  • ES Modules (ESM) – uses import

By default, Node.js assumes you are using CommonJS unless you tell it otherwise.

This is the error I faced.

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

This is the fix

type:module in package.json file


Thank You!