Failed to minify the code from this file
For people that still face this issue, here I found a solution that worked for me; I will explain it step by step here:
Recently I involved in a project that uses an older version of create-react-app
with webpack@3
and uglifyJsPlugin
in it's webpack configuration. While I worked with the project the main issue and problem raised when I installed other npm packages and I worked with them for a while in dev mode. After I've done my tasks on them, when I wanted to build the project, I faced with the headache of:
cannot minify code from this file blah blah blah...
The problem raised from minifying the js files so t thought that if I change the configuration of webpack.config.prod
to change the minification process of it, then I would be able to solve the problem. So I checked the webpack.config.prod
file and I saw that it uses the uglifyJsPlugin
for minification. I changed the configuration to use terser-webpack-plugin
and I got another error that would state that this pkg is for webpack@4
. Finally I ended up using terser-webpack-plugin-legacy
for my webpack@3
configuration and it worked perfectly. Please note that my create-react-app
was ejected.
For those you are facing the problem. First check your package.json whether you are using React-script 1.x. If so try upgrade to 2.x.x.
From the official Troubleshooting docs npm run build fails to minify
npm run build fails to minify Before
[email protected]
, this problem was caused by third partynode_modules
using modern JavaScript features because the minifier couldn't handle them during the build. This has been solved by compiling standard modern JavaScript features insidenode_modules
in[email protected]
and higher.If you're seeing this error, you're likely using an old version of
react-scripts
. You can either fix it by avoiding a dependency that uses modern syntax, or by upgrading toreact-scripts@>=2.0.0
and following the migration instructions in the changelog.
Upgrade by.
npm install --save --save-exact [email protected]
or
yarn add --exact [email protected]