Skip to content

[BUG] AppInsights breaks Angular v20.3.* local development #2643

Closed

Description

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

  protected readonly appInsights: ApplicationInsights;

  constructor() {
    this.appInsights = new ApplicationInsights({
      config: {
        instrumentationKey: '<InstrumentationKeyHere>'
      }
    });
  }

Then run the dev server and viewing the browser dev tool console you will see the error.

  • npm start

  • OS/Browser: Windows, Chrome and Edge

  • SDK Version [e.g. 22]: 3.3.9

  • How you initialized the SDK:

    this.appInsights = new ApplicationInsights({
      config: {
        instrumentationKey: '<InstrumentationKeyHere>'
      }
    });

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.

Example repo: Angular20.3WithAppInsights

Activity

  1. JensTybergheinBooku commented on Sep 12, 2025

    @JensTybergheinBooku

    I have the same issue. Did downgrade to 20.2.0 for now.

  2. stepkillah commented on Sep 12, 2025

    @stepkillah

    Same issue after updating to 20.3

  3. MSNev commented on Sep 12, 2025

    @MSNev
    Collaborator

    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.

  4. dougclutter commented on Sep 12, 2025

    @dougclutter

    I'm seeing this too.
    Created a repo.
    HTH

  5. MSNev commented on Sep 12, 2025

    @MSNev
    Collaborator

    Hi All, Do any of the suggested workaround(s) (all for your bundling configuration) work / resolve the issue?

  6. willyt150 commented on Sep 13, 2025

    @willyt150
    Author

    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 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.

  7. OldShaterhan commented on Sep 15, 2025

    @OldShaterhan

    Based on comment for: angular/angular-cli#31198, this may be introduced by: angular/angular-cli#31123

  8. CCMKarthik1611 commented on Sep 15, 2025

    @CCMKarthik1611

    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

    Image
  9. stigstar commented on Sep 16, 2025

    @stigstar

    Confirming the issue in our environment.

    Environment:

    • Angular CLI 20.3.x (Vite/esbuild pipeline)
    • Node 20.16.0 (Windows dev machine)
    • Browser: Chrome (latest)
    • @microsoft/applicationinsights-web tried: 3.3.9 and pinned set of 3.0.0 packages

    Extra diagnostics:

    • Lazy dynamic import + setTimeout still fails before our init code runs (error occurs during module evaluation).
    • Monkey patching Object.defineProperty globally or around the dynamic import does not prevent the error.
  10. willyt150 commented on Sep 16, 2025

    @willyt150
    Author

    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.

  11. MSNev commented on Sep 16, 2025

    @MSNev
    Collaborator

    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...

  12. MSNev commented on Sep 17, 2025

    @MSNev
    Collaborator

    Further guesses which is suggesting the issue above is what is occurring

  13. chris-elta commented on Sep 18, 2025

    @chris-elta

    Reverting the build in angular.json is one workaround for me:

    "builder": "@angular-devkit/build-angular:browser"

    "outputPath": {
                  "base": "<path>"
                },
    

    -> "outputPath": "<path>"

    remove: "browser": "<path to>/main.ts"
    add: "main": "<path to>/main.ts"

    Add to development build configuration:

    "development": {
                  "buildOptimizer": false,
                  "optimization": false,
                  "vendorChunk": true,
                  "extractLicenses": false,
                  "sourceMap": true,
                  "namedChunks": true
                },
    
  14. d-koppenhagen commented on Sep 18, 2025

    @d-koppenhagen

    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.

  15. chris-elta commented on Sep 18, 2025

    @chris-elta

    I am just using the reverted build locally while I wait for a patch

  16. willyt150 commented on Sep 22, 2025

    @willyt150
    Author

    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)

  17. locked as resolved and limited conversation to collaborators on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions