angular-cli: UglifyJS breaking ng build --prod

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.2 node: 8.5.0 os: darwin x64 @angular/animations: 4.4.3 @angular/common: 4.4.3 @angular/compiler: 4.4.3 @angular/core: 4.4.3 @angular/forms: 4.4.3 @angular/http: 4.4.3 @angular/platform-browser: 4.4.3 @angular/platform-browser-dynamic: 4.4.3 @angular/router: 4.4.3 @angular/cli: 1.4.2 @angular/compiler-cli: 4.4.3 @angular/language-service: 4.4.3 typescript: 2.3.4

Repro steps.

One part of the problem is I can’t find the root of it, building with ng build --prod --sourcemaps, still doesn’t reference the area in the code which doesn’t work

The log given by the failure.

ng build --prod

Date: 2017-09-20T13:43:50.815Z
Hash: 50c525c6fe0425118ede Time: 93360ms chunk {0} polyfills.02292696f70cecd900dd.bundle.js (polyfills) 190 kB {4} [initial] [rendered] chunk {1} main.fc82f1345284e30cbd13.bundle.js (main) 5.98 MB {3} [initial] [rendered] chunk {2} styles.122ee5153af13aed7be2.bundle.css (styles) 122 kB {4} [initial] [rendered] chunk {3} vendor.1f1e29f52bc669b282ae.bundle.js (vendor) 2.63 MB [initial] [rendered] chunk {4} inline.a2a6d04122157473c4e7.bundle.js (inline) 1.45 kB [entry] [rendered]

ERROR in main.fc82f1345284e30cbd13.bundle.js from UglifyJs TypeError: Cannot set property ‘fixed’ of undefined at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:5584:25) at TreeWalker._visit (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1339:24) at AST_This._walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:480:24) at AST_Dot.eval (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1061:29) at TreeWalker._visit (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1343:21) at AST_Dot._walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1060:24) at AST_Dot.walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:483:21) at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:5722:31) at TreeWalker._visit (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1339:24) at AST_ForIn._walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:653:24) at walk_body (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:530:17) at AST_BlockStatement.eval (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:541:13) at TreeWalker._visit (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1343:21) at AST_BlockStatement._walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:540:24) at AST_BlockStatement.walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:483:21) at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:5697:31) at TreeWalker._visit (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1339:24) at AST_If._walk (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:843:24) at walk_body (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:530:17) at AST_Function.eval (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:771:13) at eval (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:1340:21) at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/hugodes/src/core-front/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:5665:21)

Also worth noting, that when I do a ng build --dev, and open the main.bundle.js, there is no reference to the term “fixed” anywhere. So I really cant trace the problem.

Desired functionality.

That the ng build --prod works without problem. Failing that, I’d like to get some more info from --sourcemaps, because right now, the stacktrace references a file that does not exist

Mention any other details that might be useful.

I can’t link the project as it’s private, but I wouldn’t mind sending a copy of the source code to someone on the angular-cli team privately.

Things I tried:

  • Updating @angular/cli doens’t solve the issue.
  • rm -rf /node_modules && rm package-lock.json && npm cache clear --force && npm install doesn’t work
  • adding uglify-js@2 to package.json doesn’t work
  • I’ve been at it for a long time, so I’ve gone through most of the google search results, trying everything without success.

Package.json

{
  "name": "front",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "gulp sass && ng serve -e=local",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "angular2-jwt": "^0.2.3",
    "aws-sdk": "^2.119.0",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "file-saver": "^1.3.3",
   "intl": "^1.2.5",
    "mydatepicker": "^2.0.31",
    "ng2-charts": "^1.6.0",
    "rxjs": "^5.4.2",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.4.2",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": [
      "node",
      "file-saver"
    ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@hugodes Sorry for the delay. I was able to look into this further and this appears to be an issue with the uglifyjs-webpack-plugin itself. I traced it to this line in version 0.4.6 (the latest stable version). Instead of ast = compress.compress(ast); that line should be ast = ast.transform(compress);.

Version 1.0 of the plugin doesn’t appear to have the issue but it is currently in beta and is currently only used in the CLI if using a 1.5 RC and targeting ES2015.

The uglify bug in the repro was reported and fixed in uglify-es here and is in uglify-es@3.x which is used by uglifyjs-webpack-plugin@1.x.

uglifyjs-webpack-plugin@0.4.6 uses uglify-js@2.8.29 and does not have this fix. 3.x is the current branch of uglify-js, and the 2.x branch of uglify-js is no longer maintained.

Regarding https://github.com/angular/angular-cli/issues/7756#issuecomment-336452435, ast = compress.compress(ast); is indeed correct. Had transform been used instead of compress the net effect would be to disable reduce_vars which coincidentally would have avoided the error in question.

not my lucky day, still get error with uglify-js after change ‘es5’ to ‘es2015’ image image No problem with: ng serve, ng build, ng build --aot But failed at: ng build --prod.

I’m moving forward from 1.4.3 to 1.5 beta 4 only because of this error. now after changing target from ‘es5’ to ‘es2015’ it still got that error

This may or may not be the issue but something to check and a common cause for uglifyjs errors in the current stable version of the CLI is the presence of packages containing es2015+ javascript. Also, version 1.5 will include support for enabling a full es2015 build pipeline.

@clydin Thanks again for your response, but would there be a way of preserving that main.fc82f1345284e30cbd13.bundle.js file for after the build so I can analyse it ?

I tried the --sourcemaps option with no success.

So this looks like a crash within uglifyjs itself. It appears to be due to some form of unexpected syntax. Unfortunately, the stack trace doesn’t appear to be very helpful in tracing the actual location within uglifyjs. I’d suggest raising an issue over there as they might be able to provide some addition insight into the actual cause of the crash.