0

I am trying to learn to use webpack with react, while compiling I am getting this error.

ERROR in ./App.js

Module parse failed: D:\Reactjs\App.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React from 'react';
|
| class App extends React.Component {

My webpack.config

module.exports ={
entry:"./App.js",

output: {
    path:__dirname,
    filename:'app.js'
},

module:{
    loader:[{
        test: /\.es6\.js$/, loader: "babel-loader",


    exclude: /node_modules/,
    query: {
      optional: ['runtime'],
      presets:['stage-0', 'es2015', 'react']
    }
  }
],
resolve: {
  extensions: ['', '.js', '.jsx']
}
 }
 };
3
  • Did you tried to change the order in the presets setting? Like [ 'es2015', 'stage-0', 'react']? Commented May 5, 2016 at 14:47
  • still the same result. Commented May 5, 2016 at 15:05
  • Associate the source folder by including include:/<source_folder>/. Let me know if it works. Commented May 5, 2016 at 18:33

2 Answers 2

1

I believe that regex for the test is wrong. It should be test: /\.es6|\.js$/, loader: "babel-loader". Without the | it won't match App.js!

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

Comments

0

Try replacing the "query" part with this:

query: {
   optional: ['runtime'],
   stage: 0
}

Otherwise, I think you have to install presets npm install babel-preset-es2015 --save-dev. See here: https://stackoverflow.com/a/33470546/1043475

Comments

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.