Home > OS >  Node.js: cannot find module ... imported from
Node.js: cannot find module ... imported from

Time:12-01

This makes no sense. The file exists, but i just cannot import it.

The error

The code

The folder structure:

CodePudding user response:

If your importation alias is really a node modules you just have to import it like this "import alias from 'alias' ".

CodePudding user response:

According to Node.js Documentation

You must either change the filename extension of the module to be .mjs, so change alias.js to be alias.mjs (and change the import as appropriate)

OR, you can add this config option to package.json:

"type": "module"

This will allow you to use include instead of require syntax.

  • Related