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']
}
 }
 };
Rakesh A
  • 1
  • 2

2 Answers2

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!

lovelikelando
  • 7,593
  • 6
  • 32
  • 50
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

Community
  • 1
  • 1
Rick Jolly
  • 2,949
  • 2
  • 23
  • 31