babel watch SyntaxError: Unexpected token

佐手、 提交于 2019-11-29 15:27:10
Tom

I had a similar issue the other day. It seems that babel now needs some additional plugins to work with react.

See the answer in this SO question: babel-loader jsx SyntaxError: Unexpected token

command:

babel --watch assets/js/ --out-dir dist/js/ --presets react

or package.json:

{
    "name": "myweb",
    "version": "1.0.0",
    "babel": {
        "presets": ["react"]
    }
}

Which version of babel you have? If you upgraded to 6, you have to add react preset...

{
    test: /\.js$/,
    exclude: /node_modules/,
    loader: "babel",
    query:
    {
      presets:['react', 'es2015', 'stage-0']
    }
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!