Title: @ngtools/webpack keeps a `const enum` import when it rewrites the import declaration ("export ... was not found") · Issue #34760 · angular/angular-cli · GitHub
Open Graph Title: @ngtools/webpack keeps a `const enum` import when it rewrites the import declaration ("export ... was not found") · Issue #34760 · angular/angular-cli
X Title: @ngtools/webpack keeps a `const enum` import when it rewrites the import declaration ("export ... was not found") · Issue #34760 · angular/angular-cli
Description: Which @angular/* package(s) are the source of the bug? @ngtools/webpack (via @angular-devkit/build-angular, browser builder) Is this a regression? Yes. The last version that works is @angular-devkit/build-angular 22.1.9. It fails from 22...
Open Graph Description: Which @angular/* package(s) are the source of the bug? @ngtools/webpack (via @angular-devkit/build-angular, browser builder) Is this a regression? Yes. The last version that works is @angular-devki...
X Description: Which @angular/* package(s) are the source of the bug? @ngtools/webpack (via @angular-devkit/build-angular, browser builder) Is this a regression? Yes. The last version that works is @angular-devki...
Opengraph URL: https://github.com/angular/angular-cli/issues/34760
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@ngtools/webpack keeps a `const enum` import when it rewrites the import declaration (\"export ... was not found\")","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\n@ngtools/webpack (via @angular-devkit/build-angular, `browser` builder)\n\n### Is this a regression?\n\nYes. The last version that works is @angular-devkit/build-angular 22.1.9. It fails from 22.2.0 through 22.3.0 (the latest at the time of writing), whatever the @angular/* framework version: build-angular 22.1.9 with Angular 22.2.0 works, and build-angular 22.2.0 with Angular 22.1.8 fails.\n\n### Description\n\nWhen one import statement brings in a `const enum` together with a runtime value that is used only in type positions (for example a class that is only a constructor parameter type), the webpack build fails:\n\n```\n./src/app/app.component.ts:1:0-34 - Error: export 'Period' (imported as 'Period') was not found in './period' (possible exports: PeriodFormatter)\n```\n\n```ts\n// period.ts\nimport { Injectable } from '@angular/core';\n\nexport const enum Period {\n\tMonth = 'month',\n\tQuarter = 'quarter',\n}\n\n@Injectable({ providedIn: 'root' })\nexport class PeriodFormatter {\n\tformat(period: string): string {\n\t\treturn `Period: ${period}`;\n\t}\n}\n\n// app.component.ts\nimport { Component } from '@angular/core';\nimport { Period, PeriodFormatter } from './period';\n\n@Component({ selector: 'app-root', template: '\u003cp>{{ label }}\u003c/p>' })\nexport class AppComponent {\n\tprotected readonly label: string;\n\n\tconstructor(formatter: PeriodFormatter) {\n\t\tthis.label = formatter.format(Period.Month);\n\t}\n}\n```\n\nWhat seems to happen, judging from `elide_imports.ts`: `PeriodFormatter` is only referenced from a type node, so its specifier is classed as an unused runtime value and the declaration is rewritten without it. The comment there notes that TypeScript skips its own import elision for a declaration a transformer replaced. `Period` counts as used (`Period.Month` is an identifier reference), so it is kept, but TypeScript has inlined the const enum and would normally drop the specifier. The rewritten declaration still imports `Period`, which has no runtime export.\n\nNotes:\n- The constructor parameter is not essential: any runtime value used only in type positions in the same statement triggers it, for example a field typed `PeriodFormatter | undefined`.\n- Not needed: a barrel, tsconfig `paths`, or any non-default compiler option. `ngc` alone emits the file correctly.\n- Possibly related: #34594 (22.2.6), which fixed type-only specifiers but not this case.\n- Workarounds: a regular `enum`, or importing the const enum in its own import statement.\n\n| @angular/* | @angular-devkit/build-angular | result |\n| --- | --- | --- |\n| 22.1.8 | 22.1.9 | builds |\n| 22.2.0 | 22.1.9 | builds |\n| 22.1.8 | 22.2.0 | fails |\n| 22.2.0 | 22.2.0 | fails |\n| 22.2.4 – 22.2.6 | 22.2.4 – 22.2.7 | fails |\n| 22.2.7 | 22.2.8 | fails |\n| 22.3.0 | 22.3.0 | fails |\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://github.com/IT-CASADO/const-enum-elision-repro\n\n`npm ci && npm run build`\n\n### Please provide the exception or error you saw\n\n```\n./src/app/app.component.ts:1:0-34 - Error: export 'Period' (imported as 'Period') was not found in './period' (possible exports: PeriodFormatter)\n```\n\n### Please provide the environment you discovered this bug in\n\n```\nAngular CLI : 22.2.7\nAngular : 22.2.6\n@angular-devkit/build-angular : 22.2.7\nTypeScript : 6.0.3\nNode : 24.22.3\nOS : Windows 11\n```","author":{"url":"https://github.com/IT-CASADO","@type":"Person","name":"IT-CASADO"},"datePublished":"2026-11-19T17:18:37Z","url":"https://github.com/angular/angular-cli/issues/34760"}
| 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:32eb847f-9ebd-4485-2e8e-4d01aa76748c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0B4:21BD98:2A63405:35D0753:6B01DE5C |
| html-safe-nonce | d8ca52e254da76f6ce49771bc02565b1ae53697f363427f3bd8908525fa365cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEI0OjIxQkQ5ODoyQTYzNDA1OjM1RDA3NTM6NkIwMURFNUMiLCJ2aXNpdG9yX2lkIjoiNjI2OTI2NzExODQxMjM4OTk4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ac3a108aef9840b1b3a9f41b41f92b210b6f87d9355ff147f1cc761fb2607c8e |
| hovercard-subject-tag | issue:6495148368 |
| 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/34760/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb26ccb441fa7ac1a4b35adac0176f0f02569749151e16b5067de566a5038246/angular/angular-cli/issues/34760 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb26ccb441fa7ac1a4b35adac0176f0f02569749151e16b5067de566a5038246/angular/angular-cli/issues/34760 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? @ngtools/webpack (via @angular-devkit/build-angular, browser builder) Is this a regression? Yes. The last version that works is @angular-devki... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IT-CASADO |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width