I am trying to use webpack with react but am getting this error:
ERROR in ./app/main.js
Module parse failed: /Users/me/app/main.js Line 2: Unexpected token
You may need an appropriate loader to handle this file type.
| //npm
| import React               from 'react';
This is the webpack config section of interest:
test: /\.jsx?$/,
        include: path.join(__dirname, 'src'),
        loader: 'babel-loader',
        query: {
            presets: ['es2015', 'react']
and the package.json:
"devDependencies": {
    "autoprefixer-loader": "^3.1.0",
    "babel-core": "^6.1.20",
    "babel-loader": "^6.1.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "jest": "^0.1.40",
    "webpack": "^1.12.4",
    "webpack-dev-server": "^1.12.1",
    "css-loader": "^0.22.0",
    "style-loader": "^0.13.0"
  },
  "dependencies": {
    "babel-polyfill": "^6.1.19",
    "history": "^1.17.0",
    "react": "^0.14.2",
    "react-dom": "^0.14.2",
    "react-mdl": "^1.0.4",
    "react-router": "^1.0.2"
  }
                Looking at the path in the error message
Module parse failed: /Users/me/app/main.js Line 2: Unexpected token
it seems that the module is not inside the src folder. However, you explicitly specified that only modules inside path.join(__dirname, 'src') should passed through the babel loader.
Adjust include so that it will also include main.js.
loaders: [{
        test: /\.jsx?$/,
        loader: 'babel',
        query: {
            presets: ['es2015', 'react']
        }
    }]
This is my config for the loader. One big difference in your config is the naming of the loader. Try 'babel' instead of 'babel-loader'. Next possible error could be your version. Update babel-loader (to 6.2.0).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With