search

Home  >  Q&A  >  body text

javascript - About es6 module issues, file import and export

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.

曾经蜡笔没有小新曾经蜡笔没有小新2731 days ago780

reply all(2)I'll reply

  • typecho

    typecho2017-06-26 10:52:41

    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().

    reply
    0
  • 高洛峰

    高洛峰2017-06-26 10:52:41

    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.

    reply
    0
  • Cancelreply