Answer the question
In order to leave comments, you need to log in
UglifyJs error when building ReactJS app?
Hello everyone, I just decided to build production, ran npm run build... and got an error:
ERROR in js/app.js from UglifyJs
Invalid assignment [js/app.js:26191,31]
const renderNode = (node, key) => {
if (node.nodeName === '#text') {
return node.value;
}
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
}
{
test: /\.js/,
include: /node_modules/,
use: ['babel-loader']
}
Answer the question
In order to leave comments, you need to log in
Babel needs to specify the settings (preset) according to which the code will be transpiled.
Documentation for using babel-loader :
{
test: /\.js$/,
exclude: /node_modules|/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
}
babel-preset-env
, which automatically determines the required polyfills, etc.... Accordingly, it also needs to be included in the application: npm install --save-dev babel-preset-env
This is a bug, unfortunately the latest version of UglifyJs does not support any es6. You either need to translate to the old JS, and if you still don’t want this, install the plugin separately from webpack. Everything worked for me on this version:"uglifyjs-webpack-plugin": "^0.4.3",
As a result, I added to the production config:
{
test: /\.js$/,
exclude: /src/,
include: /node_modules/,
use: ['babel-loader']
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question