DEV Community

Hasan TEZCAN
Hasan TEZCAN

Posted on

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

If you want to use import instead of require you need to add module part to your package.json

"type":"module"  
Enter fullscreen mode Exit fullscreen mode

But don't forget you need to import with file extension.


import { ErrorMessage } from "../alerts.js"; // WORK

import { ErrorMessage } from "../alerts"; // WONT WORK!
Enter fullscreen mode Exit fullscreen mode

SOURCE: https://stackoverflow.com/a/67105989/10694425

Top comments (1)

Collapse
 
hopsken profile image
Hopsken

Thanks man, you saved my life!