“unexpected token import” in Nodejs5 and babel?

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

    Involve following steps to resolve the issue:

    1) Install the CLI and env preset

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

    2) Create a .babelrc file

    {
      "presets": ["env"]
    }
    

    3) configure npm start in package.json

    "scripts": {
        "start": "babel-node ./server/app.js",
        "test": "echo \"Error: no test specified\" && exit 1"
      }
    

    4) then start app

    $ npm start
    

提交回复
热议问题