Tuesday, September 6, 2016

Module build failed: SyntaxError: Unexpected token

When you run `webpack` with React, you might encounter the following error:

Module build failed: SyntaxError: Unexpected token

Install `babel-preset-react` as follows:

sudo npm install babel-preset-react --save

add `query` to `webpack.config.js` as follows:

module.exports = {
  ...
  module: {
    loaders: [
      ...
      {
        test: /\.js$/,
        loader: 'babel',
        query: {
          presets: ['react']
        }
      }
    ]
  }
};

Reference:
http://stackoverflow.com/questions/33460420/babel-loader-jsx-syntaxerror-unexpected-token

No comments:

Post a Comment