I'm trying to use Webpack to transpile some source files written using ES6 syntax and JSX. However, when I run the Webpack command, I get the following error.
ERROR in ./app/App.jsx
Module parse failed: ./app/App.jsx Line 5: Unexpected token
You may need an appropriate loader to handle this file type.
| 'use strict';
|
| import React from 'react';
| import { RouteHandler } from 'react-router';
|
@ multi main
As you'll see below, I'm using the babel-loader, yet it seems to me that the loader isn't able to handle the 'import' syntax. Any idea why this might be happening?
Here's a look at our basic file structure.
--/app
----/components
------/shared
--------NavigationBar.js
----App.jsx
--webpack.config.js
--package.json
Here's our package.json file.
// package.json
{
"scripts": {
"start": "webpack-dev-server --hot --inline",
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"react-hot-loader": "^1.3.0",
"webpack": "^1.12.6",
"webpack-dev-server": "^1.12.1"
},
"dependencies": {
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.0"
}
}
Here's our webpack.config.js file.
// webpack.config.js
module.exports = {
context: __dirname + '/app',
entry: './App.jsx',
output: {
filename: 'app.js',
path: __dirname + '/dist',
},
module: {
loaders: [
{
test: /\.js?$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
};
And finally, here's /app/App.jsx
// App.jsx
'use strict';
import React from 'react';
import { RouteHandler } from 'react-router';
import NavigationBar from './components/shared/NavigationBar';
class App extends React.Component {
render() {
return (
<div>
<NavigationBar />
<RouteHandler />
</div>
);
}
}
export default App;
Let me know if you need any more information to diagnose the problem. Thanks in advance for the help.