babel watch SyntaxError: Unexpected token

前端 未结 3 1844
生来不讨喜
生来不讨喜 2020-12-21 03:56

When I uses babel to watch a jsx file. But there is a syntax error.

Before that, I uses react-tools to watch, and everything is fine.

SyntaxError: as         


        
相关标签:
3条回答
  • 2020-12-21 04:14

    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']
        }
      }
    
    0 讨论(0)
  • 2020-12-21 04:32

    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

    0 讨论(0)
  • 2020-12-21 04:36

    command:

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

    or package.json:

    {
        "name": "myweb",
        "version": "1.0.0",
        "babel": {
            "presets": ["react"]
        }
    }
    
    0 讨论(0)
提交回复
热议问题