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),
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.
![Error [ERR_MODULE_NOT_FOUND]: Cannot find module Error [ERR_MODULE_NOT_FOUND]: Cannot find module](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc3WtfojKx8GOq6TNv8arWkzm1sPeDdsSMzzuPjkAGKREvR9LBbZuODktKFkvZcUac1F37-7ZzEgUDu0_bTudZut8pLCrEI59YoYAV0r-TqvzQLxKvZroZ2uesE_lWFNjgd7c5UDcfkDl55JdOgSicb-1JUVWhBGOvFwour4GXmCkzQl9HHIs_iGh0Tpo/s16000-rw/can-not-find-module-error.webp)
![throw new ERR_MODULE_NOT_FOUND(  ^  Error [ERR_MODULE_NOT_FOUND]: Cannot find module Error [ERR_MODULE_NOT_FOUND]: Cannot find module](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyJkimAQGZwNZMf7r6KeRfUrAS3fkQfsJilbGThyphenhyphenchhwRBRHOAdT-1Ws-Kr_xrHiqR1_ecaZFWIUWURtiHq8SAFEaUWDrooxn2MEIaT5Faw11bvvVmgpK8P8MyrGXZHf9HnGoGUL-EqGlKMGXWyUa7NYThZMZXgx4FaWYRqLkUQiqJR8HtUGbyK4cm53c/s16000-rw/error-ss.webp)
