Skip to content

Heap corruption error on windows when createCompilerPlugin is called before serveWithVite #31973

@Aukevanoost

Description

@Aukevanoost

Command

build, serve

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

v19.x

Description

Ok so this is a complex one, I've already lost a couple of days on this.

Native federation is using the "createCompilerPlugin" to create reusable artifacts (read dependencies) to be used in the Angular application. Now we know this is kind of an "own risk" scenario, especially since it's in the private folder of the @angular/build package but I am slowly losing it.

Some context
When we do "ng serve" on our own builder, which is basically a wrapper around the default angular build, we use ESbuild to build some packages that we want to re-use across Angular micro frontends. The code can be found in our esbuild-adapter.ts and our builder.ts. The interesting part is that we don't get an error when we remove the AngularCompilerPlugin which we use to pre-build our artifacts.

The error
Since Angular 20, we have the issue that during the serveWithVite and to be precise in the line where vite is imported., an heap error occurs. We thought it could be ESbuild since it's also used in the vite package, but all our tries have been without result so far.

Whe have an issue with all the context. Note: that all assumptions so far were wrong. Even after ng21, the issue still persists. I thought it was a race condition when closing/disposing the compiler-plugin but this is not the case.

Now I know micro frontends and using the private part of the @angular/build is for our own risk, but I would never expect a heap error. Does anyone know how this could happen or what could cause this? Final note: It is a race condition so it happens every now and then, about 40% of the ng serve builds. It happens only on windows and you can recognize the error by the build/serve just stopping without any error.

All help is welcome, thanks a bunch in advance.

Minimal Reproduction

We have a reproducable repo: https://github.com/berkon/ng-serve-crash-reproduction (it also crashes when you update to ng21).

just npm ci and npm start. Even updating to ng21 doesn't help

Exception or Error

Process finished with exit code -1073740940 (0xC0000374)

Your Environment

Just windows 10+, reest can be seen in the repository

Anything else relevant?

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