Versions
Output from: `ng --version`:
Angular CLI: 1.6.4
Node: 7.0.0
OS: win32 x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.4
@angular-devkit/build-optimizer: 0.0.38
@angular-devkit/core: 0.0.25
@angular-devkit/schematics: 0.0.48
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.4
@schematics/angular: 0.1.13
@schematics/schematics: 0.0.13
typescript: 2.6.2
webpack: 3.10.0
Windows 7
### Repro steps
I can build my project in devmode, but when I try to compile my project in AOT mode with
ng build --prod
I get the following error.
- I've cleared the npm cache
- removed complete node_modules folder
- I've structured my App into small modules, when I comment out nearly all modules the error is still there => is AOT trying to compile the hole app when I don't use the module ?
### Observed behavior
ERROR in main.6a43ba34eae25a3e2b53.bundle.js from UglifyJs TypeError: str.replace is not a function at make_string (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5634:19)
at encode_string (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5678:19) at Object.print_string (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6091:27) at print_property_name (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7179:20)
at eval (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7211:17) at doit (eval at <anonymous>
(C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6152:13)
at AST_ObjectKeyVal.eval (eval at <anonymous>
(C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6159:13)
at AST_ObjectKeyVal.AST_Node.print (eval at <anonymous>
(C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5414:18)
at eval (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1),<anonymous>:7115:22)
at Array.forEach (native)
at eval (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7109:29)
at eval (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5912:19)
at OutputStream.with_indent (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5877:38)
at Object.with_block (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5911:9)
at eval (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7108:48)
at doit (eval at <anonymous> (C:\TFS\DEV\30_Production\TestProjekt\0.2_ng5Update\10_Gui\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6152:13)
### Desired behavior
I can build the project with AOT
### Mention any other details that might be useful (optional)
We have the same problem. However we now enforce following packages to make the build work again:
It seems the new release of uglify-es (3.3.7) done last weekend is creating the issue. I hope this helps somebody in getting his production build running again.
Thank you for research, @rbluethl and @rdnscr! Your solution resolves the issue.
While the issue exists in Angular CLI dependencies, just add
"uglify-es": "3.3.5"
to devDependencies in package.json.Please, pay attention that you may need to run
npm cache clean --force
and remove package-lock.json before runningnpm install
.@filipesilva @clydin It would be very helpful if a new flag were added to angular-cli to disable uglify in webpack:
That way users could upload the problematic unminified webpack bundle file(s) into a bug report for simple diagnosis.
@filipesilva made a write up how to do this for an earlier version: https://github.com/angular/angular-cli/issues/8571#issuecomment-346998807
The issue was resolved in uglify-es 3.3.8.
This is an uglify-es bug. Stick to version 3.3.5 using a shrinkwrap file as a temporary workaround.
https://github.com/angular/angular-cli/issues/9206 https://github.com/mishoo/UglifyJS2/issues/2783