Skip to content

ESBuild creates variables and functions in global scope #32113

@mathisuniversal

Description

@mathisuniversal

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

When using ESBuild (application builder), main.js contains global variables/functions like this:

var Jf = Object.defineProperty, Xf = Object.defineProperties; var ep = Object.getOwnPropertyDescriptors; ...

It can be reproduced by simply running "ng new" and "npm run build". When switching back to Webpack (browser builder), everything is wrapped in an IIFE:

"use strict"; (self.webpackChunkbuild_test = self.webpackChunkbuild_test || []).push([[792], { ...

This is not an issue in a single application, but when used as a web component in combination with other Angular ESBuild apps, these variables conflict and lead to all kind of errors. AI suggests to adjust the ESBuild config, but I believe I can't do that with Angular.

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       : 21.0.3
Angular           : 21.0.5
Node.js           : 24.9.0
Package Manager   : npm 11.6.0
Operating System  : win32 x64 

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.0.3            │ ^21.0.3           │
│ @angular/cli              │ 21.0.3            │ ^21.0.3           │
│ @angular/common           │ 21.0.5            │ ^21.0.0           │
│ @angular/compiler         │ 21.0.5            │ ^21.0.0           │
│ @angular/compiler-cli     │ 21.0.5            │ ^21.0.0           │
│ @angular/core             │ 21.0.5            │ ^21.0.0           │
│ @angular/forms            │ 21.0.5            │ ^21.0.0           │
│ @angular/platform-browser │ 21.0.5            │ ^21.0.0           │
│ @angular/router           │ 21.0.5            │ ^21.0.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.15            │ ^4.0.8            |

Anything else?

No response

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