Skip to content

1.5.1 build-optimizer "TypeError: candidate.value.definition is not a function" #8571

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
mfrro opened this issue Nov 21, 2017 · 12 comments · Fixed by #8689
Closed

1.5.1 build-optimizer "TypeError: candidate.value.definition is not a function" #8571

mfrro opened this issue Nov 21, 2017 · 12 comments · Fixed by #8689
Assignees
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful

Comments

@mfrro
Copy link

mfrro commented Nov 21, 2017

Versions

Angular CLI: 1.5.1
Node: 6.11.4
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.1
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.1
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • run ng build --prod
  • don't know what this could be related to, since my project is quite large

Observed behavior

ERROR in main.c625bf1271eaaf6ccac7.bundle.js from UglifyJs
TypeError: candidate.value.definition is not a function
    at collapse (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:8275:61)
    at tighten_body (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:8110:17)
    at eval (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:12402:9)
    at AST_Node.eval [as optimize] (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7481:23)
    at Object.before (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7464:24)
    at AST_Node.eval [as transform] (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4688:43)
    at Object.before (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7459:9)
    at AST_Node.eval [as transform] (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4679:43)
    at Object.before (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7459:9)
    at AST_Node.eval [as transform] (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4590:31)
    at Object.before (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7459:9)
    at AST_Node.eval [as transform] (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\github\web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4578:25)

It worked with 1.5.0 with --build-optimizer and works with 1.5.1 when specifying --build-optimizer=false.

@sgibson53
Copy link

Having the same issue here using angular-cli 1.5.3

TypeError: candidate.value.definition is not a function
    at collapse (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:8275:61)
    at tighten_body (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:8110:17)
    at eval (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:9710:9)
    at AST_BlockStatement.eval [as optimize] (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:7481:23)
    at Compressor.before (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:7464:24)
    at AST_BlockStatement.eval [as transform] (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4606:31)
    at Compressor.before (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:7459:9)
    at AST_For.eval [as transform] (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4559:35)
    at eval (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4578:25)
    at doit (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:134:23)
    at MAP (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:160:52)
    at do_list (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4577:16)
    at eval (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4674:25)
    at Compressor.before (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:7459:9)
    at AST_Function.eval [as transform] (eval at <anonymous> (C:\dev\Web\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools\node.js:21:1), <anonymous>:4559:35)```

@kzc
Copy link

kzc commented Nov 21, 2017

This is an uglify bug: mishoo/UglifyJS#2497

@sgibson53
Copy link

Thanks @kzc for letting us know! Do you know how we might implement a workaround for angular cli? Doesn't look like it's straightforward (or even possible?) to pass uglify js options into the build process

@kzc
Copy link

kzc commented Nov 21, 2017

As a temporary workaround for this bug you could add collapse_vars: false to the uglify plugin's compress options in your webpack config.

In the case of angular-cli it would use a different syntax due to the way its webpack config file is structured. Try adding the following line after this:

    uglifyCompressOptions.collapse_vars = false;

I'm not an Angular user. @filipesilva Could you please confirm this is the right place for this setting?

@filipesilva filipesilva self-assigned this Nov 21, 2017
@filipesilva filipesilva added blocked P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Nov 21, 2017
@filipesilva
Copy link
Contributor

Hey @kzc, than you for letting us know! We don't expose Uglify options so this is hard to work around... The file you found is indeed the right place.

For users that want a more CI friendly workaround, you can downgrade from 1.5.x to 1.4.x, since the latter uses uglify-js instead of uglify-es (I assume this bug is only on uglify-es).

@kzc
Copy link

kzc commented Nov 21, 2017

The bug is present in both branches - latest uglify-es@3 and uglify-js@3.

You might try using an older version of uglify-es in your npm or yarn lock file.

@pcwa-ahendricks
Copy link

@filipesilva it would be handy if the uglify options were exposed; we are already tweaking the production.js config for compatibility with another popular web mapping library.

@phihonhu
Copy link

I got this issue too on CLI 1.5.0.
How to override the uglifyCompressOptions.collapse_vars from cli project without webpack.config.js?

@ghost
Copy link

ghost commented Nov 25, 2017

I am downgrading to 1.4.x. 😞

@kzc
Copy link

kzc commented Nov 26, 2017

[email protected] was released with a fix for this issue. Please try it out.

@filipesilva
Copy link
Contributor

@kzc awesome, thank you!

For users affected by this problem, here is how you can force your dependencies to use the [email protected].

You can't just add it as a dependency with a new version since the uglify-es is not a direct dependency.

To see what version you have, run npm list uglify-es:

$ npm list uglify-es
[email protected] D:\sandbox\master-project
`-- @angular/[email protected]
  `-- [email protected]
    `-- [email protected]

To force an indirect dependency to use a new version, you'll have to update your cache and remove the any package-locks you have. This series of commands should do it:

// Force update your cache
npm install [email protected]
npm uninstall [email protected]
// Remove node modules and package locks
rm -rf node_modules package-lock.json yarn.lock
// Reinstall dependencies
npm install

After all of this, you should be able to see the new version:

$ npm list uglify-es
[email protected] D:\sandbox\master-project
`-- @angular/[email protected]
  `-- [email protected]
    `-- [email protected]

I realize this process is cumbersome. NPM does not offer a good way to force update indirect dependencies.

I've submitted a PR to update our direct dependency (uglifyjs-webpack-plugin): webpack-contrib/uglifyjs-webpack-plugin#176.

Then Angular CLI can update to that version and everyone gets the new version of uglify-es by default.

@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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants