.babelrc configuration file is as follows
{
"presets": ["es2015"]
}
node index.js runs the following code:
import express from 'express';
Error message:
(function (exports, require, module, __filename, __dirname) { import express from 'express';
^^^^^^
SyntaxError: Unexpected token import
PHP中文网2017-06-20 10:08:53
There is a mistake in your usage method. There are many ways to use babel. The most common ones are .babelrc files, or the require('babel') method. You configured .babelrc but you did not use babel to compile you. index.js file, however the import syntax is not implemented in your existing version of node, so an error is reported
高洛峰2017-06-20 10:08:53
If node also wants to use the ES6 module specification, you need babel-register