You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
App does not start when downleveling past chrome 84 or safari 15 since angular 19 #29145
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
19.0.0-next.13
Description
Application throws an error at startup when using the webpack builder with optimizations enabled and targeting browsers like Safari < 15 or Chrome < 84.
I think it may be linked to private class fields because of the browsers version but maybe not.
Minimal Reproduction
Set up a .browserslistrc file with either Safari >= 14 or Chrome >= 83,
Configure angular.json to use the @angular-devkit/build-angular:browser builder,
Set "optimization": true and "buildOptimizer": true,
Run ng serve.
We are experiencing exactly the errors as mentioned in this issue. We need to target chrome 74 for our applications. And since upgrading to ng 19 we experienced this exact issue.
Depending on the value of useDefineForClassFields, TS will produce different representations of the static fields (in the @angular/core package) which in the end does not get transformed the same by babel and then not tree shaken the same by terser.
Note: I will only focus on the ɵprov field here but it's the same thing for other static fields.
@angular/core package content
With useDefineForClassFields: false, the static fields use static blocks:
With optimizations enabled, we can see that the previous code is now: (This is the breaking case)
classcore_Injector{}
So it looks like Babel helper _defineProperty gets tree-shaken.
And indeed if I update the pure-toplevel-functions.ts code to exclude _defineProperty from being marked as pure, everything seems to work fine.
I've opened a PR to do so. Please let me know what you think of the solution.
Why is this not happening with esbuild based builders ?
It looks like there is no usage of @babel/preset-env with esbuild builders, which means there is no downleveling and so the problem never occurs.
Am I understanding this right @alan-agius4 ? Because that would mean there is no way to target older browsers with these builders.
Activity
JeanMeche commentedon Dec 16, 2024
A correct repro : https://stackblitz.com/edit/stackblitz-starters-rkec1xbc
The runtime cause of the error is
Injectormissing a bunch of static fields.alan-agius4 commentedon Dec 16, 2024
Likely this is due to the removal of #28682 since in version 19 Safari 17 and 18 are officially supported prior versions are not.
jsaguet commentedon Dec 16, 2024
It looks like it indeed.
I thought that we could downlevel our build output by specifying a larger browsers range in browserslist.
Our customers are still massively coming from browsers versions outside of the supported range.
Will we have to move to a custom builder to enable those babel transforms going forward ?
JeanMeche commentedon Dec 16, 2024
There might by something related to terser at play as esbuild doesn't look to be impacted by this.
alan-agius4 commentedon Dec 17, 2024
I briefly reviewed this, and it appears the issue stems from the
pure-toplevel-functionsBabel transformer when applied to the@angular/corepackage.GlennLefevere commentedon Jan 3, 2025
We are experiencing exactly the errors as mentioned in this issue. We need to target chrome 74 for our applications. And since upgrading to ng 19 we experienced this exact issue.
fix: do not mark _defineProperty as pure in build output
jsaguet commentedon Jan 5, 2025
Here is what I found out regarding this issue:
The problem starts appearing at this commit angular/angular@93c3f7a
Depending on the value of
useDefineForClassFields, TS will produce different representations of the static fields (in the @angular/core package) which in the end does not get transformed the same by babel and then not tree shaken the same by terser.Note: I will only focus on the
ɵprovfield here but it's the same thing for other static fields.@angular/core package content
With
useDefineForClassFields: false, the static fields use static blocks:With
useDefineForClassFields: true, the static fields are not transformed:Build output with
useDefineForClassFields: trueWhen targeting Safari >= 15, we get the following:
When targeting Safari 14, we get the following (without optimizations)
With optimizations enabled, we can see that the previous code is now: (This is the breaking case)
So it looks like Babel helper
_definePropertygets tree-shaken.And indeed if I update the
pure-toplevel-functions.tscode to exclude_definePropertyfrom being marked as pure, everything seems to work fine.I've opened a PR to do so. Please let me know what you think of the solution.
Why is this not happening with esbuild based builders ?
It looks like there is no usage of
@babel/preset-envwith esbuild builders, which means there is no downleveling and so the problem never occurs.Am I understanding this right @alan-agius4 ? Because that would mean there is no way to target older browsers with these builders.
fix(@angular/build): do not mark _defineProperty as pure in build output
fix(@angular/build): do not mark Babel _defineProperty helper functio…
fix(@angular/build): do not mark Babel _defineProperty helper functio…
fix(@angular/build): do not mark Babel _defineProperty helper functio…
fix(@angular/build): do not mark Babel _defineProperty helper functio…
angular-automatic-lock-bot commentedon Feb 6, 2025
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.