Skip to content

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

Since the 14.x version of the Node you can use import to import the modules you need. You can use either require or import. You can’t natively mix them.

When you get this error SyntaxError: Cannot use import statement outside a module , you need to make sure your Node is of version 14.x +. If not, please update your Node in your system.

If it still doesn’t work add this to your package.json.

Advertisements
  "type": "module"

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.