[Solved] Node.js runs ES6 default import file error: import m1 from’./m1.js’ ^^ SyntaxError: Unexpected identifier

Solution: Install the plug-in to make NODE.JS support ES6 default import syntax

You can also use plug-ins to support es6

1.node.js terminal install plug-in

npm install --save-dev babel-preset- es2015
npm install --save-dev babel-register

2. Create a new .babelrc file, the configuration content is as follows

     "presets": ["es2015" ],
     "plugins" : []

3. Join in the entry file of node

require( ‘babel-register’);

After my experiment, only the first two steps can solve the problem.

Similar Posts:

Leave a Reply

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