Title: Production build optimization breaks code · Issue #11439 · angular/angular-cli · GitHub
Open Graph Title: Production build optimization breaks code · Issue #11439 · angular/angular-cli
X Title: Production build optimization breaks code · Issue #11439 · angular/angular-cli
Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Area - [x] devkit - [ ] schematics Versions Windows node v9.4.0 npm v5.6.0 Repro steps Use a third party libr...
Open Graph Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Area - [x] devkit - [ ] schematics Versions Windows node v9.4.0 npm v...
X Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Area - [x] devkit - [ ] schematics Versions Windows node v9.4.0 np...
Opengraph URL: https://github.com/angular/angular-cli/issues/11439
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Production build optimization breaks code","articleBody":"### Bug Report or Feature Request (mark with an `x`)\r\n```\r\n- [x] bug report -> please search issues before submitting\r\n- [ ] feature request\r\n```\r\n\r\n### Area\r\n```\r\n- [x] devkit\r\n- [ ] schematics\r\n```\r\n\r\n### Versions\r\nWindows \r\nnode v9.4.0\r\nnpm v5.6.0\r\n\r\n### Repro steps\r\nUse a third party library that contain non-side effect free getters.\r\nRun a production build.\r\nObserver that the code breaks at runtime, whereas it runs fine without \"optimization\".\r\n\r\nE.g.:\r\n\r\n * Scaffold a project that uses code (e.g. a third party library) that contains code that cannot be properly \"optimized\" using uglifyjs with it's default settings. E.g. code that uses \"non-pure getters\" like this:\r\n```\r\nlet object = {};\r\nObject.defineProperty(object,\"nonSideEffectFreeGetterBasedMember\", \r\n {get: function(){ console.log(\"side effect\")}});\r\n\r\n(function () {\r\n object.nonSideEffectFreeGetterBasedMember;\r\n}());\r\n```\r\n * Enable the angular build optimizer\r\n * Run the program with the build optimizer enabled and observe that the code does not work as expected anymore, because the non-pure getter has been removed and the side-effect does not happen anymore.\r\n\r\n### The log given by the failure\r\nn/a - it's a runtime issue in the application\r\n\r\n### Desired functionality\r\nThe optimization step should optimize, but never break code. The \"pure_getters\" option should be configurable and by default \"false\" should be used to guarantee best possible compatibility. If someone wants to optimize further and take the risk, that's fine, but don't break code by default: Don't be optimistic or dictate how code should work in your opinion. \r\nIdeally make it possible to exclude specific libraries from this treatment. Users may have no control over these libraries and patching them often is not an option.\r\n\r\n### Mention any other details that might be useful\r\nThis has been reported before but was always closed without comments or with a comment that the third party code should be changed to workaround this limitation in angular. This is a one-liner fix in angular, though and instead of dictating how third party code should be written, the CLI should try not to break existing code, instead. Debugging \"optimized production code\" is a PITA the gains are minimal compared to that. Make this a configurable setting and make it possible to exclude certain files or third party libraries.\r\n\r\nThese are the previous issues that all had the same cause and where closed or ignored with no further explanation:\r\nhttps://github.com/angular/angular-cli/issues/9231\r\nhttps://github.com/angular/angular-cli/issues/9221\r\nhttps://github.com/angular/devkit/issues/937\r\nhttps://github.com/angular/devkit/issues/388\r\nhttps://github.com/angular/devkit/issues/612\r\nand probably some more.\r\n\r\nWe are a library provider and we had several customers running into that issue. It's a nightmare to debug and analyze and devs expect that there is no behavior change when the \"optimizer\" is turned on. But there can be and is a change: it breaks their projects in all kinds of ways.\r\n\r\n### Proposed workaround for people affected by this bug\r\nGo and hack the buildoptimizer options in the code. Find [the line](https://github.com/angular/angular-cli/blob/3108ce30ab429cff581b888a5f88118d3400ad99/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts#L221) that sets the pure_getters option to true or \"strict\" and set it to \"false\" instead. If there is no such line, make sure that \"false\" is used (because the default is true and breaks code).","author":{"url":"https://github.com/yGuy","@type":"Person","name":"yGuy"},"datePublished":"2018-07-03T15:16:22Z","url":"https://github.com/angular/angular-cli/issues/11439"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:72e7af62-c31f-7e30-399c-bb7a0b12b205 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 897C:1C6C3E:1086E07:15D1C8C:6B010CB4 |
| html-safe-nonce | 3e5ac591c1a55027be4c8ea454456adeecc73e4857aa96e081a870b482ec97a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTdDOjFDNkMzRToxMDg2RTA3OjE1RDFDOEM6NkIwMTBDQjQiLCJ2aXNpdG9yX2lkIjoiNDcwMzI3NzYyMzczODk2MTA3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0426d485113e3779925d41621c7cc8e4577366794be1105586470ffb221c662c |
| hovercard-subject-tag | issue:337944543 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/11439/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0af922085268cae6b9c9b30652f194dc386817fa40bc23dd5180ce31865ab6d9/angular/angular-cli/issues/11439 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0af922085268cae6b9c9b30652f194dc386817fa40bc23dd5180ce31865ab6d9/angular/angular-cli/issues/11439 |
| og:image:alt | Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Area - [x] devkit - [ ] schematics Versions Windows node v9.4.0 npm v... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yGuy |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width