4

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"
  }

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2
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).

2 Comments

Whether you use "babel" or "babel-loader" doesn't make a difference.
Where does that query props comes from ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.