-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Enhancement
Copy link
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
If an injection token is defined as const TOKEN = new InjectionToken('desc')
, then it will not be tree-shaken from the production bundle, because esbuild considers the constructor to have side-effects.
This means that if it uses a factory function, the items that factory function references are also included.
This can cause large services to be included from a library even if they are unused because they are the default implementation of a token.
This can be mitigated by marking the token definition with /* @__PURE__ */
like so:
const TOKEN = /* @__PURE__ */ new InjectionToken('desc')
I believe this is something that should be fixed in either @angular/core or @angular/build, by marking the InjectionToken constructor as pure: https://esbuild.github.io/api/#pure.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 19.2.16
Node: 24.1.0 (Unsupported)
Package Manager: npm 11.3.0
OS: darwin arm64
Angular: 19.2.15
... common, compiler, compiler-cli, core, elements, forms
... platform-browser, platform-browser-dynamic, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1902.16
@angular-devkit/core 19.2.16
@angular-devkit/schematics 19.2.16
@angular/build 19.2.16
@angular/cli 19.2.16
@schematics/angular 19.2.16
ng-packagr 19.2.2
rxjs 7.8.1
typescript 5.8.3
zone.js 0.15.0
Anything else?
No response