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.
Hello, node 6 does not yet support the
import
andexport
syntax. I have not used node 8. You can try it yourself. Theexport
method in
node 6
ismodule.exports
orexports
, and the import method isrequire()
.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.