Importing node.js module - SyntaxError: Unexpected identifier Importing node.js module - SyntaxError: Unexpected identifier node.js node.js

Importing node.js module - SyntaxError: Unexpected identifier


As for node 12, you can add the property type in your package.json as

"type": "module"

and dont forget to run node with experimental-modules flag node --experimental-modules youapp.js


I was also facing the same issue. Here is how I fixed it.

I first updated my node and its package manager version using the following commands :

npm install node@latest -g

and

npm install npm@latest -g

After doing so, I went to my package.json file and added the following line before the scripts property:

"type": "module",

And last, I went back and tried to run my code using node app.js but it did not work until I used the following command:

node --experimental-modules app.js

At your side, replace app.js with your index file. Hope it also works for you

Nice coding