Node: Use ES6 Import in Node

Prue

Babel

Install babel-cli and babel-preset-env

$ npm install --save-dev babel-cli babel-preset-env

Create a .babelrc file for configuring babel.

$ touch .babelrc

Add config in .babelrc

{
  "presets": ["env"]
}

Add build script, in package.json

"scripts": {
  "build": "babel index.js -d dist"
}

Add start script, in package.json

"scripts": {
  "build": "babel index.js -d dist",
    "start": "npm run build && node dist/index.js"
}

Run script

npm start

ReferenceError: Unknown plugin “transform-runtime”

npm install babel-plugin-transform-runtime --save-dev

// .babelrc

{
  "presets": ["env"],
+ "plugins": [
+   "transform-runtime"
+ ]
}

Reference: