WebStorm: Getting ES6 to work?

Any ideas on how to use ES6 on WebStorm 10?  

Here's what I have done so far:

  1. Installed Babel.
  2. Activated babel with Settings > Tools > File watchers. checked Babel checkbox.
  3. Edit configurations > Before launch file watchers > +  then 'Run File Watchers".
  4. Set code as ES6
  5. Created the following trivial piece of code:

function* count(n){
    console.log(n);
}


This code shows up with no syntax errors, as it should. (A convenient way to make sure ES6 is turned on).

Run it, and get this ....

function* count(n){
        ^
SyntaxError: Unexpected token *
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Why? How do I get it to precompile with Babel then run?

7 comments
Comment actions Permalink

Seems you are running the original .js file instead of the compiled version produced by Babel. Please make sure to specify the compiled file as 'JavaScript file' in your Node.js run configuration

0
Comment actions Permalink

Thanks. I was wondering about that. Unfortunately, it produces this error when run:

var marked0$0 = [count].map(regeneratorRuntime.mark);
                            ^
ReferenceError: regeneratorRuntime is not defined

0
Comment actions Permalink

Please see https://github.com/babel/babel/issues/303: you need to include the regenerator runtime or the 6to5 polyfill (https://babeljs.io/docs/usage/polyfill/).You can also use 'require hook' (http://babeljs.io/docs/usage/require/) to get files transformed by Babel on-the-fly (and thus omit using babel file watcher)

0
Comment actions Permalink

Thanks. Curiously, I have the line:

require("babel/register");

And it does not seem to fix the regenerator problem (As implied by the docs you linked to). So it looks like:

require("babel/register");
function* count(n){
    console.log(n);
    yield(n);
}
0
Comment actions Permalink

do you have babel module installed locally (npm install babel)? I do not see any errors when running your code (when running original file, not the generated one)

0
Comment actions Permalink

I installed Babel both locally and npm -g

0
Comment actions Permalink

No ideas then:( You can probably try submitting a bug report to https://github.com/babel/babel/issues/

0

Please sign in to leave a comment.