Skip to content

Esbuild Builders behave differently than Webpack Builders with .js fileReplacements #28684

@dominicbachmann

Description

@dominicbachmann

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Switching from a Webpack based builder to an Esbuild based builder breaks .js fileReplacements. Esbuild based builders ignore the fileReplacements (without Error) when the allowJs flag in tsconfig compilerOptions is false or not set.

Minimal Reproduction

  1. Add a fileReplacement in angular.json which replaces a file with a .js file.
  2. Build the project with a Webpack based builder.
  3. See that the file was replaced properly.
  4. Build the project with an Esbuild based builder.
  5. See that the file was not replaced.
  6. Issue can be resolved by setting compilerOptions.allowJs to true in tsconfig.

Repro Repository

Issue occurs with ng build and ng serve.

When you build both projects you will see that the webpack builder output chunk contains {foo: "bar"} while the esbuild builder output chunks exports an empty object.

Issue can also be observed when serving both applications and comparing the log in the console.

Exception or Error

No response

Your Environment

Angular CLI: 18.2.9
Node: 20.11.1
Package Manager: npm 10.2.4
OS: darwin arm64

Angular: 18.2.8
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1802.9
@angular-devkit/build-angular 18.2.9
@angular-devkit/core 18.2.9
@angular-devkit/schematics 18.2.9
@angular/cli 18.2.9
@schematics/angular 18.2.9
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions