Skip to content

[BUG] TypeError: Cannot redefine property: name when using esbuild with keepNames: true, preventing VSCode extension telemetry from being sent #2694

@bwateratmsft

Description

@bwateratmsft

Description/Screenshot

Discovered from microsoft/vscode-containers#367 originally. Related issues:

Quoting my original issue here, but please look there for the most up-to-date:

Boring analysis: the reason it was happening was because we're using keepNames in esbuild, to make it not mangle class/function names (which we need if we want useful call stacks). Esbuild writes code into the bundle that, at load time (which is run time), tries to set the name property on the minified classes/functions to the original name.

Some of the AppInsights packages are freezing some of their stuff, which makes it impossible to set the name property. The error that was thrown (and then caught and eaten) would resemble:

TypeError: Cannot redefine property: name
at defineProperty (<anonymous>)
at __name (d:\\vscode-containers\\dist\\extension.bundle.js:8:33)
at node_modules/@microsoft/1ds-core-js/dist-es5/AppInsightsCore.js (d:\\vscode-containers\\dist\\extension.bundle.js:16157:5)
at __init (d:\\vscode-containers\\dist\\extension.bundle.js:10:56)
at node_modules/@microsoft/1ds-core-js/dist-es5/Index.js (d:\\vscode-containers\\dist\\extension.bundle.js:16819:5)
at __init (d:\\vscode-containers\\dist\\extension.bundle.js:10:56)
at d:\\vscode-containers\\dist\\extension.bundle.js:20303:57
at async getAICore (d:\\vscode-containers\\dist\\extension.bundle.js:20303:21)
at async oneDataSystemClientFactory (d:\\vscode-containers\\dist\\extension.bundle.js:20343:29)

The end result was that loading the AppInsights packages failed silently, and the AppInsights reporter never got built--so when we logged telemetry events, they were just screamed into the void.

I considered three options. The first was to build the extension as ESM, but unfortunately this just didn't work at all.

The second was to turn off keepNames...but that would negatively impact both telemetry and the issue reporter by giving us mangled names that we would have to translate after-the-fact if we wanted to investigate.

The third was Opus' idea (nice job AI!). Basically, we build the @vscode/extension-telemetry package into its own bundle, with keepNames off, and then build everything else (extension and other dependencies) into the main bundle, with an alias to rewrite imports to @vscode/extension-telemetry to point to the other bundle.

Steps to Reproduce

  1. Clone and npm install from https://github.com/microsoft/vscode-containers/tree/v2.4.0
  2. In launch.json, change DEBUGTELEMETRY env var to 0
  3. F5 and do anything in the Container Tools extension
  • OS/Browser: Any OS
  • SDK Version [e.g. 22]: (Below)
  • How you initialized the SDK:
    @vscode/extension-telemetry@0.9.9
    @microsoft/1ds-core-js@4.3.10
    @microsoft/1ds-post-js@4.3.10
    @microsoft/applicationinsights-web-basic@3.3.10

Expected behavior
Works with ESBuild without issues

Metadata

Metadata

Assignees

No one assigned

    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