Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
saeedsq opened this issue Feb 2, 2019 · 22 comments
Assignees

Comments

@saeedsq
Copy link

saeedsq commented Feb 2, 2019

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

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"})
@VassilisPallas
Copy link

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

@garster
Copy link

garster commented Feb 3, 2019

I had the same problem. Workaround worked! Thanks.

@kkitay
Copy link

kkitay commented Feb 3, 2019

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

@jamesallan626
Copy link

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

@djbaldey
Copy link

djbaldey commented Feb 3, 2019

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

@Lawrence-Wu
Copy link

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

@saeedsq
Copy link
Author

saeedsq commented Feb 3, 2019

@VassilisPallas Thanks, it fixed it

@saeedsq saeedsq closed this as completed Feb 3, 2019
@TomCosta
Copy link

TomCosta commented Feb 3, 2019

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

@erwanriou
Copy link

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....

@noircir
Copy link

noircir commented Feb 3, 2019

@erwanriou
if you've used yarn...

#6334 (comment)

@erwanriou
Copy link

@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?

@erwanriou
Copy link

@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.`

@thierrydelbart
Copy link

@erwanriou

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

@Alaricus
Copy link

Alaricus commented Feb 4, 2019

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.

@DanielCortesTX
Copy link

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

@shoesCodeFor
Copy link

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

candyrobot pushed a commit to candyrobot/product.hideaki that referenced this issue Feb 4, 2019
@nanot1m
Copy link

nanot1m commented Feb 4, 2019

For yarn users: add this to package.json

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

@mrmckeb
Copy link
Contributor

mrmckeb commented Feb 4, 2019

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.

@mrmckeb mrmckeb self-assigned this Feb 4, 2019
@mrmckeb mrmckeb reopened this Feb 4, 2019
@mrmckeb
Copy link
Contributor

mrmckeb commented Feb 4, 2019

Please track any further comments against this ticket #6334.

@mrmckeb mrmckeb closed this as completed Feb 4, 2019
@aqibbangash
Copy link

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.`

@mrmckeb
Copy link
Contributor

mrmckeb commented Feb 4, 2019

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

@facebook facebook locked and limited conversation to collaborators Feb 4, 2019
cesarsalaad added a commit to cesarsalaad/my-portfolio that referenced this issue Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests