“unexpected token import” in Nodejs5 and babel?

前端 未结 13 2124
清酒与你
清酒与你 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:15

    From the babel 6 Release notes:

    Since Babel is focusing on being a platform for JavaScript tooling and not an ES2015 transpiler, we’ve decided to make all of the plugins opt-in. This means when you install Babel it will no longer transpile your ES2015 code by default.

    In my setup I installed the es2015 preset

    npm install --save-dev babel-preset-es2015
    

    or with yarn

    yarn add babel-preset-es2015 --dev
    

    and enabled the preset in my .babelrc

    {
      "presets": ["es2015"]
    }
    

提交回复
热议问题