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

前端 未结 4 1676
别跟我提以往
别跟我提以往 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:56

    Until modules are implemented you can use the Babel "transpiler" to run your code:

    npm install --save babel-cli babel-preset-node6
    ./node_modules/.bin/babel-node --presets node6 ./your_script.js
    

    See https://www.npmjs.com/package/babel-preset-node6 and https://babeljs.io/docs/usage/cli/

    Downsides: this has various downsides, such as extra compilation time, which can be significant and you now need source maps for debugging; just saying.

提交回复
热议问题