babel: “import path from ‘path’;” error

I set up a new project to use Google’s Web Toolkit framework, which uses babel in its gulpfile.

All looks good, but I get this error

$ gulp e2e-test
[09:01:05] Requiring external module babel-register
CWD/gulpfile.babel.js:27
import path from 'path';
^^^^^^

SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at loader (CWD/node_modules/babel-register/lib/node.js:158:5)

The cause: I need a .babelrc file to make it work.

From the babel website, (https://babeljs.io/docs/setup/#installation)

$ echo '{ "presets": ["es2015"] }' > .babelrc

and now all is good.

Leave a Reply

Your email address will not be published. Required fields are marked *