Title: Libraries sometimes depend on tsickle decorator downleveling · Issue #30586 · angular/angular · GitHub
Open Graph Title: Libraries sometimes depend on tsickle decorator downleveling · Issue #30586 · angular/angular
X Title: Libraries sometimes depend on tsickle decorator downleveling · Issue #30586 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/.... @angular/compiler-cli / @angular/bazel Is this a regression? No Description Angular applications which are built with NGC but aren't setting up tsickle for decora...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/.... @angular/compiler-cli / @angular/bazel Is this a regression? No Description Angular applications which are built with NGC ...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/.... @angular/compiler-cli / @angular/bazel Is this a regression? No Description Angular applications which are built with NGC ...
Opengraph URL: https://github.com/angular/angular/issues/30586
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Libraries sometimes depend on tsickle decorator downleveling","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 bug report\r\n\r\n### Affected Package\r\n\u003c!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->\r\n\u003c!-- ✍️edit: --> The issue is caused by package @angular/....\r\n\r\n`@angular/compiler-cli` / `@angular/bazel`\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nAngular applications which are built with NGC but aren't setting up `tsickle` for decorator downleveling (e.g. don't set the `annotationsAs: \"static fields\"`), can't be rendered on the server if DOM-specific types are referenced on class members which are decorated.\r\n\r\ne.g.\r\n\r\n```ts\r\n@Directive(...)\r\nexport class MyDirective {\r\n @Input() triggerElement: HTMLElement;\r\n}\r\n```\r\n\r\nThis results in the following ES5 JavaScript output if `tsickle` is **not enabled**\r\n\r\n```js\r\n __decorate([\r\n core_1.Input(),\r\n __metadata(\"design:type\", HTMLElement)\r\n ], MyDirective.prototype, \"triggerElement\");\r\n```\r\nNotice how the `__decorate` call tries to access `HTMLELement` from a global context. This causes an exception when the following file is executed in NodeJS since DOM APIs are not available. We mock most of the DOM APIs with `domino` but providing these mocks globally so that such failures can be avoided is not common right now.\r\n\r\nBuilding the project **with tsickle** fixes the problem automatically as decorators are downleveled into a static field while `tsickle` also discards the type reference to `HTMLElement` (as it is not relevant for Angular).\r\n\r\n```js\r\nMyDirective.propDecorators = {\r\n triggerElement: [{ type: core_1.Input }]\r\n};\r\n```\r\n\r\nTL;DR: \r\n\r\n1) Everything currently works as expected within the CLI since it provides optimizations that removes the decorators anyway when using AOT mode or build-optimizer.\r\n2) It becomes an issue if a project is not built with the CLI / and does not use build-optimizer. Previously tsickle was part of the NGC workflow **by default**.. so it now causes unexpected failures. Needs documentation? See: https://github.com/angular/angular/commit/29761ea5f8e4bae68442236f4a0abc1666487a35\r\n\r\n**How is Angular Bazel affected?**\r\n\r\nWith Bazel it is not possible to opt-in for tsickle's decorator downleveling. Tsickle can be enabled by passing the `bazelOptions: {tsickle: true}`, but that comes with more tsickle transformations which aren't desired. e.g. type imports are rewritten to `goog.requireType`.\r\n\r\n## 🔬 Minimal Reproduction\r\n\r\nhttps://github.com/devversion/ngc-without-tsickle\r\n\r\n## 🔥 Exception or Error\r\n\u003cpre>\u003ccode>__metadata(\"design:type\", HTMLElement)\r\n ^\r\nReferenceError: HTMLElement is not defined\r\n\u003c/code>\u003c/pre>\r\n\r\n\r\n## 🌍 Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>Latest: 8.0.0-rc.4\u003c/code>\u003c/pre>\r\n\r\n**Anything else relevant?**\r\n\r\n","author":{"url":"https://github.com/devversion","@type":"Person","name":"devversion"},"datePublished":"2019-05-21T09:26:26Z","url":"https://github.com/angular/angular/issues/30586"}
| 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:45bf4c4e-b73a-0099-93af-0f04d43d8865 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF72:8AE25:1D242B:26504A:6B018A09 |
| html-safe-nonce | 528dc6a06b5e97a0b84fea4f756e9ba1a6ccf084981fb29d71ed8e44f8dcff5e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjcyOjhBRTI1OjFEMjQyQjoyNjUwNEE6NkIwMThBMDkiLCJ2aXNpdG9yX2lkIjoiNjAwMTk3ODIyOTcwMTgzOTM2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9fe98537a9ad5de44700471635bf0f2eaf2eb7ec383d3b5918473a27b6d40459 |
| hovercard-subject-tag | issue:446511402 |
| 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/30586/issue_layout |
| twitter:image | https://opengraph.githubassets.com/14ad1e77623ab50c7e43aca4bb87873006586413276f9d640f85e5e75ee35097/angular/angular/issues/30586 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/14ad1e77623ab50c7e43aca4bb87873006586413276f9d640f85e5e75ee35097/angular/angular/issues/30586 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/.... @angular/compiler-cli / @angular/bazel Is this a regression? No Description Angular applications which are built with NGC ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devversion |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width