javascript - About es6 module issues, file import and export
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-26 10:50:41
0
2
768

When trying the es6 module, using node main to run
The following problems occurred:
(function (exports, require, module, __filename, __dirname) { import myFunc from
'myFunc';

                                                          ^^^^^^

SyntaxError: Unexpected token import

The codes for the two files are as follows:

 // profile.js
 export default function () {
  console.log('握手export');
 };

// main.js
import myFunc from 'myFunc';
myFunc();

I’ve been looking for it for a long time but I don’t know why. I have some related questions:
(*) Does this module have to be installed with node before it can run? Can it be run on the browser side?

But it still doesn’t work after many attempts...wait for the master’s answer.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
typecho

Hello, node 6 does not yet support the import and export syntax. I have not used node 8. You can try it yourself. The
export method in node 6 is module.exports or exports, and the import method is require().

小葫芦

Node currently does not support import and export, and the latest node 8 does not support it either. If you need to use babel or webpack2, convert it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template