Languages

Node.js - Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\path1' imported from C:\path2

3 points
Asked by:
Mariam-Barron
811

Can you help me with the following error?

Error [ERR_MODULE_NOT_FOUND]: Cannot  find module 'C:\path\to\file1.js' imported from C:\path\to\file2.js

I'm using ES Modules in my Node.js project (I've added "type": "module" to package.json file).

1 answer
3 points
Answered by:
Mariam-Barron
811

You probably didn't specify the file extension. When you are using ES Modules import/export in pure JS in Node.js, you need to remember that when you are importing modules.

Practical example

Instead of:

import { myVariable } from './myModule';

use:

import { myVariable } from './myModule.js';

 

See also

  1. Node.js - enable ES Modules (enabling import/export) 

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join