Skip to content
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

Cannot investigate ng build --prod UglifyJs failure #5741

Closed
calbot opened this issue Mar 29, 2017 · 43 comments
Closed

Cannot investigate ng build --prod UglifyJs failure #5741

calbot opened this issue Mar 29, 2017 · 43 comments
Assignees
Labels
effort2: medium (days) freq1: low Only reported by a handful of users who observe it rarely P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity1: confusing type: faq

Comments

@calbot
Copy link

calbot commented Mar 29, 2017

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
Copy link
Author

calbot commented Mar 30, 2017

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.

@sethdn
Copy link

sethdn commented Apr 1, 2017

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]

@ghost
Copy link

ghost commented Apr 17, 2017

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.

@filipesilva
Copy link
Contributor

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 filipesilva self-assigned this May 3, 2017
@filipesilva filipesilva added effort2: medium (days) freq1: low Only reported by a handful of users who observe it rarely severity1: confusing P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels May 3, 2017
@steveschmitt
Copy link

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.

@TeaTimeForever
Copy link

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

@filipesilva
Copy link
Contributor

@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!

@yaahor
Copy link

yaahor commented May 24, 2017

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?

@calbot
Copy link
Author

calbot commented May 24, 2017 via email

@yaahor
Copy link

yaahor commented May 24, 2017

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?

@smac89
Copy link

smac89 commented Jun 29, 2017

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

@ghost
Copy link

ghost commented Aug 5, 2017

@smac89 What does the sm flag do?

@filipesilva
Copy link
Contributor

-sm is the alias for --sourcemap.

@ghost
Copy link

ghost commented Aug 5, 2017 via email

@kirillgroshkov
Copy link

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)

@steveschmitt
Copy link

@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.

@toregua
Copy link

toregua commented Aug 23, 2017

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 ?

@hanafidesarr
Copy link

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

@steveschmitt
Copy link

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

@hanafidesarr
Copy link

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

@jscharett
Copy link

Using mishoo/UglifyJS2#harmony resolves the build issue, but doesn't not resolve the issue for users that need to target ES5. There needs to be a way to target ES5 not only for TypeScript, but for JavaScript as well.

@fabien-chevalley
Copy link

Hi,
I have a similar issue on my project when I try to run "ng build --prod"

ERROR in main.ec6db48d8ba59a5ab59d.bundle.js from UglifyJs
Unexpected token: name (Utils) [main.ec6db48d8ba59a5ab59d.bundle.js:29,6]
ERROR in vendor.7ad64718ce2c67850294.bundle.js from UglifyJs
Unexpected token: name (AuthGuard) [vendor.7ad64718ce2c67850294.bundle.js:818,6]

I'm targeting es6, so I add the following dev-dependencies, clear the modules and reinstall... but I still have the error.

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

If someone has an idea to help me, it's welcome.

@jpconsi
Copy link

jpconsi commented Sep 14, 2017

@steveschmitt trick of using --sm to generate the source map provided the clue that my ngx-infinite-scroll had an issue. Prior to the uglify-js error I was having a problem when building ngx-infinite-scroll that it could not find index.js so I moved the node_modules/ngx-infinite-scroll/modules/ngx-infinite-scroll.js to node_modules/ngx-infinite-scroll/index.js For me, the would have been fine because my tsconfig.json target was es2015, but for other reasons I changed my tsconfig.json to target es5 and needed to go back and move node_modules/ngx-infinite-scroll/modules/ngx-infinite-scroll.es5.js to node_modules/ngx-infinite-scroll/modules/index.js. Once I did that change the below uglify error went away.
ERROR in vendor.5c96b46238fbfbd9e2a9.bundle.js from UglifyJs Unexpected token: name (PositionResolver) [/demo/~/ngx-infinite-scroll/index.js:9,0][vendor.5c96b46238fbfbd9e2a9.bundle.js:20572,6]

@maiasmith
Copy link

maiasmith commented Sep 29, 2017

I was having this problem as well
ERROR in vendor.c45fa8f7cd4783bc8895.bundle.js from UglifyJs Unexpected token: name (radix) [vendor.c45fa8f7cd4783bc8895.bundle.js:45505,8]

And solved it by first looking into the sourcemaps (ng build --prod --sm), as suggested by @steveschmitt) which led me to discover that it was a problem with the generatorics npm package

ERROR in vendor.c45fa8f7cd4783bc8895.bundle.js from UglifyJs Unexpected token: name (radix) [/Users/maiasmith/git_repos/presentation-template-ng2/~/generatorics/generatorics.js:43,0][vendor.c45fa8f7cd4783bc8895.bundle.js:45505,8]

I removed the package, and problem solved!

@hiepxanh
Copy link
Contributor

i have no "uglify-js" in my package.json to replace what should i do ??

@youssefgh
Copy link

@fabien-chevalley did you find any solution ? i applied the sugestions above but seems like uglify-js is still used

@youssefgh
Copy link

@steveschmitt i can't find "uglify-js" in package.json because it's a nested dependency of angular-cli though just adding it doesn't change anything for the most of us.
Any idea ? maybe you use a specific version of angular-cli that doesn't nest uglify-js ?
Thanks

@steveschmitt
Copy link

steveschmitt commented Oct 21, 2017 via email

@fabien-chevalley
Copy link

@youssefgh I try to move on Angular-Cli 1.5 to have the following modification #7610, the production build is now working, but I'm not able to serve my application #7797 anymore...

So I didn't have any solution for the moment

@youssefgh
Copy link

youssefgh commented Oct 27, 2017

I moved to cli 1.5.0-rc.2 as a workaround until 1.5 is released
For anyone having the same problem here is my changes:

  1. move to : "@angular/cli": "1.5.0-rc.2"
  2. make sure that target is set to "es2015" in tsconfig.json
  3. serve using : ng serve --aot

Thanks a lot guys for you help ;)

@FrancescoBorzi
Copy link

I got the same issue using 1.5. I tried both ng build --prod --aot and ng build --prod --aot false. The error says:

Unexpected token: name (MyService) [main.9ccecc27d4a5724997c5.bundle.js:20,6

@youssefgh
Copy link

@ShinDarth i no longer have this issue using 1.5 and even without using --aot. I think you have a different problem
can you make sure that target is set to "es2015" in tsconfig.json ?
if you still have the same issue try building with : ng build --prod --sm to see what lib is causing your error

@FrancescoBorzi
Copy link

@youssefgh I did it, in my case it's not a lib but my source code

@youssefgh
Copy link

@ShinDarth then (i think) just changing the es6+ syntax in your code to a ES2015 compliant should resolve your problem see above comment :

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.

@FrancescoBorzi
Copy link

yes I used --sm flag to check which line of my code is actually causing it, but it's this line:

export class MyService {

@youssefgh
Copy link

That is weird that a simple class in an angular project can cause this
Can you share a sample project that reproduce this error ?

@FrancescoBorzi
Copy link

@youssefgh I'm not able to reproduce the problem in other projects. Actually I'm even having troubles in reproducing it with the same project across different machines...

@iamonuwa
Copy link

iamonuwa commented Dec 3, 2017

I solved mine by removing repeated codes inside my assets folder.

@BBlackwo
Copy link

BBlackwo commented Aug 30, 2018

For those interested in Angular CLI v6.* the flag is now --source-map.

For me, source maps helped me identify a trailing comma in my function parameters that was breaking uglifyJS 🤷‍♂️.

@kengneruphine
Copy link

Hello ,

Here is the error i face after running ng build --prod.
Please can someone help me out!!

ERROR in 10.ef56b443a514b22853bd.chunk.js from UglifyJs
TypeError: Cannot set property 'fixed' of undefined
at TreeWalker.eval [as visit] (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :5584:25)
at TreeWalker._visit (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1339:24)
at AST_This._walk (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :480:24)
at AST_Dot.eval (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1061:29)
at TreeWalker._visit (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1343:21)
at AST_Dot._walk (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1060:24)
at AST_Dot.walk (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :483:21)
at TreeWalker.eval [as visit] (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :5722:31)
at TreeWalker._visit (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1339:24)
at AST_ForIn._walk (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :653:24)
at walk_body (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :530:17)
at AST_Function.eval (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :771:13)
at eval (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1340:21)
at TreeWalker.eval [as visit] (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :5665:21)
at TreeWalker._visit (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :1339:24)
at AST_Function._walk (eval at (/home/ruphine/FineractCN/integration-tests/fineract-cn-fims-web-app/node_modules/webpack/node_modules/uglify-js/tools/node.js:27:1), :765:24)

@hpardess
Copy link

hpardess commented Dec 5, 2018

I had following error,

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

and it is fixed with ng build --prod --source-map
later I get heap error and node --max_old_space_size=12000 ./node_modules/.bin/ng build --prod --source-map command solved that too.

@ghost
Copy link

ghost commented Jan 26, 2019

Update:

Only with --build-optimizer=false and --source-map I was able to get the location of the error

ng build --prod --named-chunks --verbose --build-optimizer=false --source-map

If I build my app, I am getting Unexpected token: punc ()):

$ ng build --prod
                                                                                         
Date: 2019-01-26T22:32:18.173Z
Hash: b5bcaa2123bb6718baf2
Time: 28403ms
chunk {0} runtime.0935b498984fda7c2e4f.js (runtime) 2.23 kB [entry] [rendered]
chunk {1} common.78f3e0cd7d0f774768aa.js (common) 583 bytes  [rendered]
chunk {2} main.2ae834dcaf8208d7aecd.js (main) 970 kB [initial] [rendered]
chunk {3} polyfills.588b345e325a2549098e.js (polyfills) 61.7 kB [initial] [rendered]
chunk {4} styles.088d5b7a7a0995d1df55.css (styles) 85.4 kB [initial] [rendered]
chunk {5} 5.7e99fa00323b77c4e1c2.js () 3.82 MB  [rendered]
chunk {6} 6.954a4978d0c6c411bb2f.js () 6.3 kB  [rendered]

ERROR in 5.7e99fa00323b77c4e1c2.js from Terser
Unexpected token: punc ()) [5.7e99fa00323b77c4e1c2.js:27338,4]

If I use --source-map, the error seems to disappear:

$ ng build --prod --source-map 
                                                                                                               
Date: 2019-01-26T22:31:44.106Z
Hash: 51afc4cc158a10e520c6
Time: 45390ms
chunk {0} runtime.b29d49d6f279fff34f57.js, runtime.b29d49d6f279fff34f57.js.map (runtime) 2.29 kB [entry] [rendered]
chunk {1} common.70409de1782336a79716.js, common.70409de1782336a79716.js.map (common) 639 bytes  [rendered]
chunk {2} main.01e8ea6a2dd33c4e19d8.js, main.01e8ea6a2dd33c4e19d8.js.map (main) 970 kB [initial] [rendered]
chunk {3} polyfills.22294cd4941de9604b91.js, polyfills.22294cd4941de9604b91.js.map (polyfills) 61.7 kB [initial] [rendered]
chunk {4} styles.97ca4c55e9ba593fdf4c.css, styles.97ca4c55e9ba593fdf4c.css.map (styles) 85.5 kB [initial] [rendered]
chunk {5} 5.33da963a3dd6decc5efc.js, 5.33da963a3dd6decc5efc.js.map () 1.9 MB  [rendered]
chunk {6} 6.85bd192b02e86745d878.js, 6.85bd192b02e86745d878.js.map () 6.35 kB  [rendered]

So that's that.

I have already removed node_modules and installed everything from scratch without success.

@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort2: medium (days) freq1: low Only reported by a handful of users who observe it rarely P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity1: confusing type: faq
Projects
None yet
Development

No branches or pull requests