Skip to content

SyntaxError: Cannot use import statement outside a module – How to fix this error in Node.js?

SyntaxError: Cannot use import statement outside a module – This error occurs when you use ES6 imports in your node.js code.

Advertisements

To fix this just add “type”: “module” to your package.json file.

{
.
.
"type": "module"
.
.
}
See also  How to Dockerize your node.js application?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.