Angular-cli: ng build --prod throwing exception

Created on 2 Feb 2019  Β·  12Comments  Β·  Source: angular/angular-cli

🐞 Bug report

Command (mark with an x)


- [ ] new
- [x ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No

Description

Building production for angular crashes because of Terser

πŸ”¬ Minimal Reproduction

Create a new angular app with "ng new my-app" as described on the angular.io get started
page and it will crash.

πŸ”₯ Exception or Error


`ERROR in common.162374785956ac8f24a6.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (C:\path\node_modules\terser-webpack-plugin\dist\minify.js:162:59)
    at module.exports (C:\path\node_modules\terser-webpack-plugin\dist\worker.js:16:41)
    at handle (C:\path\node_modules\worker-farm\lib\child\index.js:44:8)
    at process. (C:\path\node_modules\worker-farm\lib\child\index.js:51:3)
    at process.emit (events.js:182:13)
    at emit (internal/child_process.js:812:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
`

🌍 Your Environment


$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.1.4
Node: 10.13.0
OS: win32 x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.1.4
@ngtools/webpack                  7.1.4
@schematics/angular               7.1.4
@schematics/update                0.11.4
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

Anything else relevant?

blocked devkibuild-angular critical regression bufix

Most helpful comment

This problem is related to https://github.com/terser-js/terser/issues/251. Fix submitted in https://github.com/terser-js/terser/pull/254 should address this.

Workaround by @sodatea in https://github.com/vuejs/vue-cli/issues/3407#issuecomment-459985313:

For npm users: run npm i [email protected]
For yarn users: add the following field to package.json and then rerun yarn:

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

All 12 comments

I have the same error.

This error is solved by installing the previous version of terser

npm install [email protected]

Note: This is a temporary solution

This problem is related to https://github.com/terser-js/terser/issues/251. Fix submitted in https://github.com/terser-js/terser/pull/254 should address this.

Workaround by @sodatea in https://github.com/vuejs/vue-cli/issues/3407#issuecomment-459985313:

For npm users: run npm i [email protected]
For yarn users: add the following field to package.json and then rerun yarn:

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

also getting this with for the first time after updating to 7.3.0

FYI Provided solution with "resolution" in package.json worked on:
CLI: "@angular/cli": "^7.3.0"
ANGULAR: "@angular/common": "~7.2.3"

Problem only occurs on not-default build configurations e.g.:
ng build --configuration=staging

I also face this error when I run ng build --prod --build-optimizer

[ERROR] ERROR in 0.41a9786d57a2f2254213.js from Terser
[INFO] Time: 61783ms
[ERROR] TypeError: Cannot read property 'minify' of undefined
[INFO] chunk {0} 0.41a9786d57a2f2254213.js () 47.1 kB  [rendered]

I also face this error when I run ng build --prod --build-optimizer

[ERROR] ERROR in 0.41a9786d57a2f2254213.js from Terser
[INFO] Time: 61783ms
[ERROR] TypeError: Cannot read property 'minify' of undefined
[INFO] chunk {0} 0.41a9786d57a2f2254213.js () 47.1 kB  [rendered]
Angular CLI: 7.3.0
Node: 10.11.0
OS: win32 x64
Angular: 7.2.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.0
@angular-devkit/build-angular     0.13.0
@angular-devkit/build-optimizer   0.13.0
@angular-devkit/build-webpack     0.13.0
@angular-devkit/core              7.3.0
@angular-devkit/schematics        7.3.0
@angular/cli                      7.3.0
@ngtools/webpack                  7.3.0
@schematics/angular               7.3.0
@schematics/update                0.13.0
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

error:

ERROR in runtime.fbc6620cf651a6d9e991.js from Terser
TypeError: Cannot read property 'minify' of undefined

damnnn this is breaking my build....

Same here, getting this after updating from 7.2.3 to 7.3.0

it was caused by an error in terser. There is a workaround listed in the issue but it appears they have deployed a fix a couple hours ago anyway.
https://github.com/terser-js/terser/pull/254#issuecomment-460223373

Hello all,

Both terser and terser-webpack-plugin have released updates that address the problem. We are in the process of updating the versions we use in https://github.com/angular/angular-cli/pull/13589. This should completely prevent the bug once our fix is released.

You can force your existing projects to use the new terser version directly right now as well:

  • npm users do npm install --save [email protected] followed by npm uninstall --save terser
  • yarn users add "resolutions": { "terser": "3.16.1" } to your package.json, run yarn, then remove the resolution from package.json

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmurphzyo picture jmurphzyo  Β·  3Comments

sysmat picture sysmat  Β·  3Comments

ericel picture ericel  Β·  3Comments

gotschmarcel picture gotschmarcel  Β·  3Comments

brtnshrdr picture brtnshrdr  Β·  3Comments