ES2015 “import” not working in node v6.0.0 with with --harmony_modules option

前端 未结 4 1675
别跟我提以往
别跟我提以往 2020-11-29 01:59

I am using node v6.0.0 and wanted to use ES2016 (ES6). However I realized that the \"import\" syntax is not working. Isn\'t \"import\" fundamental to for writing modular cod

4条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 02:34

    As is stated above, ES6 modules are not implemented yet.

    It appears to be a non-trivial issue to implement ES6 modules in a way that would be backward-compatible with Common JS modules, which is the current Node.js module syntax.

    However, there is a draft of an implementation, that introduces a new file extension - .mjs - for a files containing ES6 modules.

    Also, there is a counter-proposal that present an alternative approach of declaring all files with ES6 modules in package.json like so:

    {
        "modules.root": "/path/to/es6/modules"
    }
    

提交回复
热议问题