angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Cannot investigate ng build --prod UglifyJs failure

Open calbot opened this issue 9 years ago • 43 comments

Bug Report or Feature Request (mark with an x)

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

Versions.

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 6.9.4
os: darwin x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/compiler-cli: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/platform-server: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0

Repro steps.

I run... ng build --prod

But uglify fails and there's no way to investigate it because the dest folder isn't created on this failure. Specifically trying to investigate Unexpected token operator «=», expected punc «,» .

chunk    {0} 0.d17559b9dc1f9710df9e.chunk.js 977 kB {1} {2} [rendered]
chunk    {1} 1.3fb611ed62385f1481c5.chunk.js 762 kB {0} {2} [rendered]
chunk    {2} main.6670c5c330feeaa5af25.bundle.js (main) 760 kB {5} [initial] [rendered]
chunk    {3} scripts.bf4293b30b91e67e776a.bundle.js (scripts) 124 kB {6} [initial] [rendered]
chunk    {4} styles.5d73c197136fb409042d.bundle.css (styles) 228 bytes {6} [initial] [rendered]
chunk    {5} vendor.1f74f5a264bded28ec07.bundle.js (vendor) 3.63 MB [initial] [rendered]
chunk    {6} inline.51a70f6c591274413cac.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in 0.d17559b9dc1f9710df9e.chunk.js from UglifyJs
Unexpected token operator «=», expected punc «,» [0.d17559b9dc1f9710df9e.chunk.js:9262,39]

The log given by the failure.

Desired functionality.

Would like some more context. The intermediate files should not be deleted on an UglifyJs failure because there's not much to go on.

Mention any other details that might be useful.

This error started for me today after I tried to update to angular 4 and the new angular cli.

calbot avatar Mar 29 '17 21:03 calbot

I believe this was caused by a module I was importing ('text-mask-core') which used default parameters in the source. I was importing directly from the module's src folder instead of the dist which is compatible. However, this was basically fixed by accident for me and I think it would be good if the error message was improved help investigate these kind of issues.

calbot avatar Mar 30 '17 16:03 calbot

Same issue. I may have a bad import but I can't tell because the UglifyJs error refers to a file that's never saved, I have no dist folder after this output. This also started for me after upgrading to cli 1.0 and angular 4.0

chunk    {0} polyfills.542b1cc3540cd92d2faf.bundle.js (polyfills) 231 kB {4} [initial] [rendered]
chunk    {1} main.7aa1f2df5f02a96ec7a8.bundle.js (main) 433 kB {3} [initial] [rendered]
chunk    {2} styles.affbae4a63d3ceba7182.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk    {3} vendor.26896e0d308d49cc81c8.bundle.js (vendor) 2.82 MB [initial] [rendered]
chunk    {4} inline.310ee8c9f916bf58dfc3.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in vendor.26896e0d308d49cc81c8.bundle.js from UglifyJs
Unexpected token: punc ()) [vendor.26896e0d308d49cc81c8.bundle.js:1806,12]

sethdn avatar Apr 01 '17 18:04 sethdn

I've had this error some time ago. This fixed it for me: adding/replacing the uglify-js dependency in package.json: "uglify-js": "github:mishoo/UglifyJS2#harmony"

NB: the "unexpected token operator" mentioned in the error is arbitrary.

ghost avatar Apr 17 '17 15:04 ghost

I agree that it would be good to have better errors for this sort of stuff, but that's what UglifyJS gives us. Maybe we can replace it with something else in the future.

filipesilva avatar May 03 '17 12:05 filipesilva

If you add the sourcemaps flag, e.g. ng build --prod -sm, then the error shows the source file line causing the problem, instead of just the bundle line.

steveschmitt avatar May 05 '17 20:05 steveschmitt

For me helps @calbot solution. I also have used text-mask-core source code instead of dist (utilities have many useful functions).

TeaTimeForever avatar May 16 '17 09:05 TeaTimeForever

@steveschmitt ah of course, I didn't think of that at all. --prod defaults to no sourcemaps, so without turning them on there isn't a way to get the source. That's the real answer. Cheers!

filipesilva avatar May 16 '17 10:05 filipesilva

When I run global [email protected] ng build -prod, then building complete successfully. But when I try to run local [email protected] node_modules\.bin\ng build -prod, then error is thrown ERROR in vendor.c6a3588f344ea41b381f.bundle.js from UglifyJs Unexpected token: name (Simple) [vendor.c6a3588f344ea41b381f.bundle.js:8858,6].

File tsconfig.json:

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

File tsconfig.app.json:

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

Can somebody explain why is this happening?

yaahor avatar May 24 '17 19:05 yaahor

Try the source map option which was mentioned earlier to see where the error came from.

On 24 May 2017 at 12:47, yaahor [email protected] wrote:

When I run global [email protected] ng build -prod, then building complete successfully. But when I try to run local [email protected] node_modules.bin\ng build -prod, then error is thrown ERROR in vendor.c6a3588f344ea41b381f.bundle.js from UglifyJs Unexpected token: name (Simple) [vendor.c6a3588f344ea41b381f. bundle.js:8858,6].

File tsconfig.json:

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

File tsconfig.app.json:

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

Can somebody explain why is this happening?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5741#issuecomment-303831647, or mute the thread https://github.com/notifications/unsubscribe-auth/AHywlJAQzJzNhcJtA2x1GdRQfkzgo2Riks5r9IlbgaJpZM4MtkQ9 .

calbot avatar May 24 '17 19:05 calbot

ERROR in vendor.18a7b680aa4a2a94950a.bundle.js from UglifyJs
Unexpected token: name (Simple) [./~/cbor/lib/simple.js:9,0][vendor.18a7b680aa4a2a94950a.bundle.js:8889,6]

Line 9 of file ./~/cbor/lib/simple.js: class Simple {

"cbor" is dependency of "autobahn" library what is used in my project. Is it "crob" library issue? Why building by global ang local angular-cli of the same version behave differently?

yaahor avatar May 24 '17 20:05 yaahor

If you use the -sm flag to know what file is causing problems, and you have access to the file, the solution (atleast for me) was to not use es6+ features in that file. Removing all es6+ features made this error go away.

Thanks to this comment

smac89 avatar Jun 29 '17 06:06 smac89

@smac89 What does the sm flag do?

ghost avatar Aug 05 '17 00:08 ghost

-sm is the alias for --sourcemap.

filipesilva avatar Aug 05 '17 09:08 filipesilva

Lol that makes sense. I can probably figure out how to add source map to webpack config prod mode.

On Aug 5, 2017 2:10 AM, "Filipe Silva" [email protected] wrote:

-sm is the alias for --sourcemap.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5741#issuecomment-320432362, or mute the thread https://github.com/notifications/unsubscribe-auth/AX5Xbs3xzn-VmaAChSdmZWhRx4YtbZRIks5sVDGDgaJpZM4MtkQ9 .

ghost avatar Aug 05 '17 14:08 ghost

Brilliant advice about -sm! Now I figured that pify package broke my build since it's using es6 and UglifyJS chokes on it. Still need to figure how to make UglifyJS work... (I'm using Angular CLI)

kirillgroshkov avatar Aug 10 '17 09:08 kirillgroshkov

@kirillgroshkov You can try replacing the uglify-js in your package.json with

    "uglify-js": "github:mishoo/UglifyJS2#harmony",

It's an experimental version of Uglify that works with ES6.

steveschmitt avatar Aug 10 '17 13:08 steveschmitt

A use angular cli but i have no "uglify-js" in my package.json to replace. Do you know how to deal with that situation ?

toregua avatar Aug 23 '17 08:08 toregua

i have same issues, i remove node_modules, then npm install again, and success

hanafidesarr avatar Aug 24 '17 09:08 hanafidesarr

You should be able to just remove node_modules/uglify-js and then npm install.

steveschmitt avatar Aug 24 '17 09:08 steveschmitt

Yes,remove node_modules folder. I've tried just now. i build use 'npm run build -- --prod'

hanafidesarr avatar Aug 24 '17 09:08 hanafidesarr