“unexpected token import” in Nodejs5 and babel?

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

    @jovi all you need to do is add .babelrc file like this:

    {
      "plugins": [
        "transform-strict-mode",
        "transform-es2015-modules-commonjs",
        "transform-es2015-spread",
        "transform-es2015-destructuring",
        "transform-es2015-parameters"
      ]
    }
    

    and install these plugins as devdependences with npm.

    then try babel-node ***.js again. hope this can help you.

提交回复
热议问题