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
[BUG] AppInsights breaks Angular v20.3.* local development #2643
Description/Screenshot @microsoft/applicationinsights-web breaks running the local development Angular server after upgrading to Angular 20.3.* packages with error Cannot redefine property: name. Prevents anything from working/running.
Uncaught TypeError: Cannot redefine property: name
at defineProperty (<anonymous>)
at __name (chunk-TJFVSI2U.js:20:33)
at AnalyticsPlugin.js:57:10
Steps to Reproduce
Create a brand new Angular 20 application w/ modules (using angular cli global version 20.3.1)
ng new cannot-redefine-property --standalone=false --ai-config "none" --style "scss" --ssr false --zoneless false
Install ApplicationInsights-JS
npm i @microsoft/applicationinsights-web
Add Application Insights creation to the app.ts constructor
Expected behavior
Error should not occur and the site should run and display.
Additional context
This issue only started occurring when upgrading from Angular 20.2.* versions to 20.3.* in order to resolve dependency vulnerabilities.
This is seeming like an Angular packaging issue, I have copilot looking at possible "workaround" to avoid the angular issue. Especially since we don't explicitly use __name
Angular uses helper functions like __name() to annotate or wrap functions with metadata. In 20.3, it appears that __name() is trying to redefine the name property of a function that was already defined without configurable: true. This wasn't an issue in 20.2, so the implementation of __name() or related internal utilities likely changed.
I've updated the description with my repo, created following the reproduction steps. Also here: Angular20.3WithAppInsights. It's slightly different than Doug Clutter (@dougclutter)'s example as his is the standalone version, while I'm dealing with modules.
I've tried/looked into all the workarounds utilizing the example repo and none of the suggested workarounds work.
Here are my findings:
Option 1: We're using esbuild not webpack as that's the direction Angular is moving to.
It would be nice to have the Option 1 installation dependency note up with Option 1, instead of needing to read all the way down. But I'm not sure if this workaround is viable or not.
Option 2: The angular.json is already configured with optimization: false for development, and the default configuration for serve is development - Not a viable workaround
Option 3: The tsconfig.json is already targeting ES2022, so this did NOT resolve anything. (also my actual project is also already using ES2022 for target and module and experienced the issue as well) - Not a viable workaround
Option 4:--optimization doesn't exist as an argument for the angular cli- Not a viable workaround
I also created another branch attempting to utilize the Angular plugin that the document recommends considering, and it results in the same issue.
We are also experiencing the same issue after upgrading to Angular version 20.3.0. Please review the attached sample and provide a solution to resolve the issue.
Looking at the issue MSNev filed for Angular, they've closed it with a PR completed to revert the breaking change. So hopefully we'll have a new Angular 20.* version that resolves this issue.
Yeah, my gut feeling is that the underlying issue (based on this location AnalyticsPlugin.js:57) is that as part of initialization we perform a "deep" Object.freeze() on our default configuration options (line 57 seems to align with this code) this is to ensure that our defaults can't be changed by either us (accidently) or any 3rd party. Our defaults are applied during initialization to the "merged" config and are copies (not references -- part of why we freeze them to ensure we don't accidently include references)....
So I (think) what is happening is that the Angular code is either attempting to update (or add) this object (we don't have a name property)... Just Guessing...
I think reverting to the older angular builder is not a really good solution. Meanwhile the Angular CLI team reverted the breaking changes which broke the build. See: angular/angular-cli#31198
Activity
JensTybergheinBooku commentedon Sep 12, 2025
I have the same issue. Did downgrade to 20.2.0 for now.
stepkillah commentedon Sep 12, 2025
Same issue after updating to 20.3
MSNev commentedon Sep 12, 2025
This is seeming like an Angular packaging issue, I have copilot looking at possible "workaround" to avoid the angular issue. Especially since we don't explicitly use
__nameAngular uses helper functions like __name() to annotate or wrap functions with metadata. In 20.3, it appears that __name() is trying to redefine the name property of a function that was already defined without configurable: true. This wasn't an issue in 20.2, so the implementation of __name() or related internal utilities likely changed.
dougclutter commentedon Sep 12, 2025
I'm seeing this too.
Created a repo.
HTH
MSNev commentedon Sep 12, 2025
Hi All, Do any of the suggested workaround(s) (all for your bundling configuration) work / resolve the issue?
willyt150 commentedon Sep 13, 2025
Nev (@MSNev)
I've updated the description with my repo, created following the reproduction steps. Also here: Angular20.3WithAppInsights. It's slightly different than Doug Clutter (@dougclutter)'s example as his is the standalone version, while I'm dealing with modules.
I've tried/looked into all the workarounds utilizing the example repo and none of the suggested workarounds work.
Here are my findings:
Option 1: We're using
esbuildnotwebpackas that's the direction Angular is moving to.Option 2: The angular.json is already configured with
optimization: falsefor development, and the default configuration forserveis development - Not a viable workaroundOption 3: The tsconfig.json is already targeting ES2022, so this did NOT resolve anything. (also my actual project is also already using ES2022 for target and module and experienced the issue as well) - Not a viable workaround
Option 4:
--optimizationdoesn't exist as an argument for the angular cli- Not a viable workaroundI also created another branch attempting to utilize the Angular plugin that the document recommends considering, and it results in the same issue.
OldShaterhan commentedon Sep 15, 2025
Based on comment for: angular/angular-cli#31198, this may be introduced by: angular/angular-cli#31123
CCMKarthik1611 commentedon Sep 15, 2025
We are also experiencing the same issue after upgrading to Angular version 20.3.0. Please review the attached sample and provide a solution to resolve the issue.
angular20.3.0 sample.zip
stigstar commentedon Sep 16, 2025
Confirming the issue in our environment.
Environment:
Extra diagnostics:
Object.definePropertyglobally or around the dynamic import does not prevent the error.willyt150 commentedon Sep 16, 2025
Looking at the issue MSNev filed for Angular, they've closed it with a PR completed to revert the breaking change. So hopefully we'll have a new Angular 20.* version that resolves this issue.
MSNev commentedon Sep 16, 2025
Yeah, my gut feeling is that the underlying issue (based on this location
AnalyticsPlugin.js:57) is that as part of initialization we perform a "deep" Object.freeze() on our default configuration options (line 57 seems to align with this code) this is to ensure that our defaults can't be changed by either us (accidently) or any 3rd party. Our defaults are applied during initialization to the "merged" config and are copies (not references -- part of why we freeze them to ensure we don't accidently include references)....So I (think) what is happening is that the Angular code is either attempting to update (or add) this object (we don't have a
nameproperty)... Just Guessing...MSNev commentedon Sep 17, 2025
Further guesses which is suggesting the issue above is what is occurring
chris-elta commentedon Sep 18, 2025
Reverting the build in angular.json is one workaround for me:
"builder": "@angular-devkit/build-angular:browser"->
"outputPath": "<path>"remove:
"browser": "<path to>/main.ts"add:
"main": "<path to>/main.ts"Add to development build configuration:
d-koppenhagen commentedon Sep 18, 2025
I think reverting to the older angular builder is not a really good solution. Meanwhile the Angular CLI team reverted the breaking changes which broke the build. See: angular/angular-cli#31198
I think with the next release it should be fixed.
chris-elta commentedon Sep 18, 2025
I am just using the reverted build locally while I wait for a patch
willyt150 commentedon Sep 22, 2025
I have now upgraded to @angular/cli 20.3.2 and the issue no longer occurs.
Thanks for submitting the issue with Angular Nev (@MSNev)