SyntaxError: Unexpected token import – Express

NodeJS supports import natively only experimentally, and only if your script has the .mjs extension.

That’s why the start in your package.json is referring to babel-node, which transpiles ES6 code into classic JS on-the-fly before running it. But I doubt even that command will work, because you’re not passing any presets to babel to run the script. Try this command:

nodemon --exec babel-node --presets env index.js

[OR]

Rename your file to have .mjs extension, then run this:

nodemon --experimental-modules index.mjs

Leave a Comment