I am getting an error code that is auto-generated when I use webpack and babel in a NodeJs React application:
Uncaught ReferenceError: Invalid left-hand side in assignment
Here is the offending line in the code auto-generated by babel/webpack:
"development" = 'development'; // bundle.js line 17933
If I manually delete the above line from the auto-generated code then the error goes away. But that is not a good solution for obvious reasons.
I'm using webpack 4, as shown in this excerpt from package.json:
"babel-loader": "^7.1.4",
"babel-preset-stage-0": "^6.24.1",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.12"
Here is my webpack.config.js:
module.exports = {
entry: './source/main.js',
output: {
path: __dirname,
filename: 'public/javascripts/bundle.js'
},
devtool: "inline-source-map",
module: {
rules: [
{
test: /.js?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['react', 'stage-0']
}
}
}
]
}
};
I build bundle.js like this:
node_modules/.bin/webpack --mode development
The error goes away if I keep everything the same but use webpack 3.11.0 and uninstall webpack-cli and build bundle.js like this:
node_modules/.bin/webpack
NOTE: The latest webpack 3.X versions support the webpack 4.X syntax shown in my webpack.config.js.
Details:
$ node --version
v9.8.0
$ npm --version
5.7.1