Skip to content

AOT Error: UglifyJs TypeError: str.replace is not a function at make_string #9218

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

Closed
squadwuschel opened this issue Jan 15, 2018 · 16 comments
Closed
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@squadwuschel
Copy link

squadwuschel commented Jan 15, 2018

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)

@nourson
Copy link

nourson commented Jan 15, 2018

Same issue breaks when compiling --prod due to Uglify

Output from: ng --version:

Angular CLI: 1.6.2
Node: 7.2.1
OS: win32 x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic, router

@angular/cli: 1.6.2
@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.2
@schematics/angular: 0.1.13
@schematics/schematics: 0.0.13
typescript: 2.6.2
webpack-bundle-analyzer: 2.9.2
webpack: 3.10.0

Observed behavior

ERROR in 1.c1ea63b3ae55ccf3932a.chunk.js from UglifyJs
TypeError: str.replace is not a function
at make_string 
at encode_string
at Object.print_string
at print_property_name
at eval 

@Chris380
Copy link

Same for my project, building with Angular CLI 1.6.4:
ng build works
ng build --prod fails:

ERROR in main.06ba7b57493d1c0b57a6.bundle.js from UglifyJs
TypeError: str.replace is not a function
    at make_string (eval at <anonymous>

Clearing the npm cache and removing the node_modules folder did not help.
Building a new project created with ng new works.

@squadwuschel
Copy link
Author

there seems to be something broken, in some npm modules. When I build the project on a other pc its working, because I've old node modules folder there. But with a new node_modules folder its not working anymore. Someone has broken its dependencies

@akosk
Copy link

akosk commented Jan 15, 2018

I've the same problem. This is critical issue because I am not able to create new prod build.

Angular CLI: 1.6.4
Node: 7.10.1
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.4.2
webpack: 3.10.0

ERROR in 0.d38b28484293b972e1a7.chunk.js from UglifyJs
TypeError: str.replace is not a function
    at make_string (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5634:19)
    at encode_string (eval at <anonymous> (C:\sh\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:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:609
1:27)
    at print_property_name (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:717
9:20)
    at eval (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7211:17)
    at doit (eval at <anonymous> (C:\sh\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:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6
159:13)
    at AST_ObjectKeyVal.AST_Node.print (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <an
onymous>:5414:18)
    at eval (eval at <anonymous> (C:\sh\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:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7109:29)
    at eval (eval at <anonymous> (C:\sh\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:\sh\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:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:5911:
9)
    at eval (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:7108:48)
    at doit (eval at <anonymous> (C:\sh\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:1), <anonymous>:6152:13)

@rbluethl
Copy link

This is an uglify-es bug.
Stick to version 3.3.5 using a shrinkwrap file as a temporary workaround.

#9206
mishoo/UglifyJS#2783

@rdnscr
Copy link

rdnscr commented Jan 15, 2018

We have the same problem. However we now enforce following packages to make the build work again:

  "devDependencies": {
    "@types/uglify-js": "2.6.30",
    "uglify-es": "3.3.5",
    "uglifyjs-webpack-plugin": "1.1.6"
  }

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.

@alexeykostevich
Copy link

alexeykostevich commented Jan 15, 2018

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.

{
   ...
  "devDependencies": {
    "@angular/cli": "1.6.5",
    ...
    "uglify-es": "3.3.5"
  }
}

Please, pay attention that you may need to run npm cache clean --force and remove package-lock.json before running npm install.

@kzc
Copy link

kzc commented Jan 15, 2018

This bug is probably not related to mishoo/UglifyJS#2783.

If someone is able to isolate this "str.replace is not a function at make_string" bug in a small self-contained standalone javascript test case please report it in: mishoo/UglifyJS#2790

The AST_ObjectKeyVal.AST_Node.print in the stack trace suggests it is related to object literals or class expressions.

@Brocco Brocco added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jan 15, 2018
@kzc
Copy link

kzc commented Jan 18, 2018

Uglify fix: mishoo/UglifyJS#2810

@kzc
Copy link

kzc commented Jan 18, 2018

@filipesilva @clydin It would be very helpful if a new flag were added to angular-cli to disable uglify in webpack:

ng build --prod --no-minify

That way users could upload the problematic unminified webpack bundle file(s) into a bug report for simple diagnosis.

@RingoKam
Copy link

rdnscr solution fix the build error, but some functionality in my app was broken on production built.

upgrading uglify to 3.3.8 seems to have fix the issue.

"devDependencies": {
    "@types/uglify-js": "2.6.30",
    "uglify-es": "3.3.8",
    "uglifyjs-webpack-plugin": "1.1.6"
  }

@kzc
Copy link

kzc commented Jan 23, 2018

The issue was resolved in uglify-es 3.3.8.

$ node_modules/uglify-es/bin/uglifyjs -V
uglify-es 3.3.8

$ echo 'var o={}; o[-1]=1; console.log(o);' | node_modules/uglify-es/bin/uglifyjs -c
var o={"-1":1};console.log(o);
$ node_modules/uglify-es/bin/uglifyjs -V
uglify-es 3.3.7

$ echo 'var o={}; o[-1]=1; console.log(o);' | node_modules/uglify-es/bin/uglifyjs -c
ERROR: str.replace is not a function
    at make_string

@nhustak
Copy link

nhustak commented Jan 23, 2018

I understand this has been fixed in uglify 3.3.8. I cannot get my project to update it. I have removed the lock file, cleared the cache via --force and did an install. I added 3.3.8 as a devdependency per the above comment. I end up with references to both versions in my lock file. I noticed uglifjs-webpack-plugin 1.1.6 has 3.3.7 listed as a dependency. In turn, the cli references the plugin. How do I get it to pick up 3.3.8? Thanks I'm still learning my way around npm.

I added my package.json file.

package.zip

@kzc
Copy link

kzc commented Jan 23, 2018

@filipesilva made a write up how to do this for an earlier version: #8571 (comment)

@clydin
Copy link
Member

clydin commented Jan 23, 2018

Closing as resolved by [email protected].

@clydin clydin closed this as completed Jan 23, 2018
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
@clydin clydin removed their assignment Jun 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests