James M. Lay James M. Lay - 1 year ago 75
Node.js Question

Easiest way to experiment with `import` ES6

The recent Meteor tutorials use the

aspect of ES6 a lot, and I'd like to know if there's an es6 wrapper or other simple way to experiment with this specific feature without having to create a new
npm install babel --save
npm start
, etc...

Ideally, something like this:

> echo 'import "./importme.js";' > new.js
> echo 'console.log('hi');' > import.js
> es6 new.js

I did notice babel-node, but it's complaining that import is not a valid token, and apparently it doesn't support
from the REPL.

Is there a REPL or node wrapper that supports


Answer Source

babel-node will work fine, but babel doesn't do anything out of the box since version 6. You have to install presets to opt-in to the new features.

  1. npm install babel-node
  2. npm install babel-preset-es2015 Installs the preset for ES2015 syntax.
  3. touch .babelrc Create a .babelrc file to tell babel which presets you are using

Inside your .babelrc file, add the following code:

  "presets": ["es2015"]

Now, running babel-node will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download