“unexpected token import” in Nodejs5 and babel?

前端 未结 13 2143
清酒与你
清酒与你 2020-11-30 18:40

In js file, i used import to instead of require

import co from \'co\';

And tried to run it directly by nodejs since it said import is \'shi

13条回答
  •  误落风尘
    2020-11-30 19:20

    babel-preset-es2015 is now deprecated and you'll get a warning if you try to use Laurence's solution.

    To get this working with Babel 6.24.1+, use babel-preset-env instead:

    npm install babel-preset-env --save-dev
    

    Then add env to your presets in your .babelrc:

    {
      "presets": ["env"]
    }
    

    See the Babel docs for more info.

提交回复
热议问题