Reputation: 1
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']
}
}
};
Upvotes: 0
Views: 53
Reputation: 3009
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
Upvotes: 0
Reputation: 9319
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!
Upvotes: 1