import/export statements in JavaScript not working
Hello everyone,
I'm a newbie to WebStrom. I'm working with JavaScript(ES6) and using a modular approach in my Project.
But for me, import/export statements are not working. It is giving me an error...
Unexpected token import

But if I try the same thing with require/module.exports it works fine.
N.B. - I've already changed the JS version to ES6 from Languages and Frameworks.
Please sign in to leave a comment.
This is not WebStorm but Node.js that fails. While
importis a part of ES6, native support for ES6 modules in Node.js is very limited and requires special setup - see https://nodejs.org/api/esm.html#esm_enabling. So, you have to compile your code with Babel first. Usually transpiling is a part of build process (using Gulp, Grunt, WebPack, etc.). Or, you can transpile your code on-the-fly by passing-r babel-registerto Node.js. Of course, you would still need to have all required modules installedThanks, Elena!