Create-react-app: Failed to build react app from scratch: Failed to minify the bundle. Error: static/js/main.a07f295c.chunk.js from Terser

Created on 2 Feb 2019  路  22Comments  路  Source: facebook/create-react-app

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

  • failed to minify
  • Failed to minify the bundle. Error: static/js/main.a07f295c.chunk.js from Terser
  • TypeError: Cannot read property 'minify' of undefined
  • at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)

Environment

Environment Info:

System:
OS: Linux 4.4 Ubuntu 16.04.5 LTS (Xenial Xerus)
CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 10.15.1 - /usr/bin/node
npm: 6.7.0 - /usr/bin/npm
npmPackages:
react: ^16.7.0 => 16.7.0
react-dom: ^16.7.0 => 16.7.0
react-scripts: 2.1.3 => 2.1.3
npmGlobalPackages:
create-react-app: 2.1.3

Steps to Reproduce

1.

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get -y -q update
sudo apt-get install -y nodejs
sudo apt-get install -y python build-essential
sudo npm install -g npm@latest
sudo npm install create-react-app
  1. npx create-react-app my-app
  2. cd my-app
  3. npm run build

Expected Behavior

Successful build.

Actual Behavior

Failed to compile.
Failed to minify the bundle. Error: static/js/main.a07f295c.chunk.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at compiler.run (/home/vagrant/my-app/node_modules/react-scripts/scripts/build.js:169:23)
    at finalCallback (/home/vagrant/my-app/node_modules/webpack/lib/Compiler.js:210:39)
    at hooks.done.callAsync.err (/home/vagrant/my-app/node_modules/webpack/lib/Compiler.js:226:13)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/vagrant/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/vagrant/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at onCompiled (/home/vagrant/my-app/node_modules/webpack/lib/Compiler.js:224:21)
    at hooks.afterCompile.callAsync.err (/home/vagrant/my-app/node_modules/webpack/lib/Compiler.js:553:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/vagrant/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/vagrant/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/home/vagrant/my-app/node_modules/webpack/lib/Compiler.js:550:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/vagrant/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/vagrant/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeAssets.callAsync.err (/home/vagrant/my-app/node_modules/webpack/lib/Compilation.js:1295:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/vagrant/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/vagrant/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/home/vagrant/my-app/node_modules/webpack/lib/Compilation.js:1286:32)
Read more here: http://bit.ly/CRA-build-minify

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2019-02-02T20_14_07_987Z-debug.log

Error in log file

13 verbose stack Error: [email protected] build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)

Output of running npx create-react-app my-app

npm WARN deprecated [email protected]: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated [email protected]: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
underlying tools

Most helpful comment

Well, it seems that terser is the reason. Try to install npm install [email protected] --save-dev.
The problem is being explained in this issue #6334

All 22 comments

Well, it seems that terser is the reason. Try to install npm install [email protected] --save-dev.
The problem is being explained in this issue #6334

I had the same problem. Workaround worked! Thanks.

also having this issue with a _fresh_ create-react-app. installing terser works for now

Same problem in GitLab and locally on Mac. Resolved with $ npm install [email protected]

Same problem on Debian. Resolved with $ npm install [email protected]

Same problem. Thanks for VassilisPallas. "npm install [email protected] --save-dev" resolved the problem.

@VassilisPallas Thanks, it fixed it

Solution:
npm install [email protected] --save-dev
That's it, solves!

On a heroku server, tried all this solution, but doesn't workout. Nor heroku doesn't take in count the update of the npm package, not i don't know. Shall i rethink my heroku build?

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"

when i check my npm package its confirm that the installed version is terser 3,14 and localy build are working....

@erwanriou
if you've used yarn...

https://github.com/facebook/create-react-app/issues/6334#issuecomment-460058401

@noircir unfortunatly no i don't user yarn in this project. I was relying just on npm. Shall i try to install yarn somehow just to handle this case?

@noircir

ok i fix how to do it. We have to change the script just for this case:

` "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install [email protected] --prefix client && npm run build --prefix client"

`

` Running heroku-postbuild

   > [email protected] heroku-postbuild /tmp/build_e3190506ce04ec098fd91e520951f690
   > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install [email protected] --prefix client && npm run build --prefix client

   added 1881 packages from 783 contributors and audited 36953 packages in 71.252s
   found 0 vulnerabilities

   + [email protected]
   updated 1 package and audited 36959 packages in 18.136s
   found 0 vulnerabilities


   > [email protected] build /tmp/build_e3190506ce04ec098fd91e520951f690/client
   > react-scripts build

   Creating an optimized production build...
   Compiled with warnings.`

@erwanriou

Thank you. That heroku-postbuild script worked on mine. i was also using heroku.

@erwanriou

Amazing, I was having the exact same problem. Works now. Thanks!

The workaround works, however, if you already have "terser": "^3.14.1" in your package.json and happen to delete your node_modules and do an npm install, the build will break again and you'll need to npm install [email protected] --save-dev again.

@erwanriou
This solved it for me too. I was using the MERN stack. Much appreciated.

I had the same issue with using Yarn. Switching to NPM and using Terser as a Dev dependency solved my issue

For yarn users: add this to package.json

"resolutions": {
  "terser": "3.14.1"
}

We are still tracking this issue, and waiting for either Terser or terser-webpack-plugin to release an update to resolve this. Apologies for the obvious inconvenience here.

Please track any further comments against this ticket #6334.

This fixed my issue (y)

@noircir

ok i fix how to do it. We have to change the script just for this case:

` "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install [email protected] --prefix client && npm run build --prefix client"

`

` Running heroku-postbuild

   > [email protected] heroku-postbuild /tmp/build_e3190506ce04ec098fd91e520951f690
   > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install [email protected] --prefix client && npm run build --prefix client

   added 1881 packages from 783 contributors and audited 36953 packages in 71.252s
   found 0 vulnerabilities

   + [email protected]
   updated 1 package and audited 36959 packages in 18.136s
   found 0 vulnerabilities


   > [email protected] build /tmp/build_e3190506ce04ec098fd91e520951f690/client
   > react-scripts build

   Creating an optimized production build...
   Compiled with warnings.`

I'll lock this issue, please use #6334 to discuss workarounds.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ap13p picture ap13p  路  3Comments

onelson picture onelson  路  3Comments

barcher picture barcher  路  3Comments

rdamian3 picture rdamian3  路  3Comments

fson picture fson  路  3Comments