I have this webpack.config.js
:
module.exports = { entry: './src/admin/client/index.jsx', output: { filename: './src/admin/client/static/js/app.js' }, loaders: [ { test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/, query: { optional: ['runtime'] } } ], resolve: { extensions: ['', '.js', '.jsx'] } };
...yet I still get this error:
$ webpack -v Hash: 2a9a40224beb025cb433 Version: webpack 1.10.5 Time: 44ms [0] ./src/admin/client/index.jsx 0 bytes [built] [failed] ERROR in ./src/admin/client/index.jsx Module parse failed: /project/src/admin/client/index.jsx Line 1: Unexpected reserved word You may need an appropriate loader to handle this file type. | import React from 'react'; | import AdminInterface from './components/AdminInterface';
I have:
webpack
globally and locallybabel-loader
, babel-core
, and babel-runtime
babel-loader
globally, just in caseWhy the hell is webpack seemingly ignoring babel-loader
? Or does babel-loader
not work with modules?
Update:
It looks like babel
handles the input file just fine. When I run:
./node_modules/babel/bin/babel.js ./src/admin/client/index.jsx
...it outputs ES5 as expected. Therefore, it seems to me like somehow webpack
isn't properly loading babel-loader
.
If Babel is a translator for JS, you can think of Webpack as a mega-multi-translator that works with all kinds of languages (or assets). For example, Webpack often runs Babel as one of its jobs. Another example, Webpack can collect all your inline CSS styles in your Javascript files and bundle them into one.
Webpack does not contain Babel or uglify by default. These are contained within the loaders. These are seperate npm packages you need to install used in the configuration.
We will use webpack to bundle multiple js files into a single file. Babel will be used to compile the es6 code to es5. We have used export to use the details of the Person class.
This looks like a case of operator error. My webpack.config.js
structure was not correct. Specifically, I needed to put the loader details inside of a module
section:
module.exports = { entry: './src/admin/client/index.jsx', output: { filename: './src/admin/client/static/js/app.js' }, module: { loaders: [ { test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/, query: { optional: ['runtime'] } } ], resolve: { extensions: ['', '.js', '.jsx'] } } };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With