From 1a5538e0c9cc121fa1608eb99e941bc3a5f59ad6 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:20:35 -0500 Subject: [PATCH] fix(@angular-devkit/build-angular): disable Worker wait loop for TS/NG parallel compilation in web containers When using the `application` builder, a parallel TS/NG compilation is used that is run inside a Node.js Worker. This Worker by default uses an Atomics-based wait loop to improve performance while waiting for messages. This loop relies on the synchronous API `receiveMessageOnPort`. While this works well in Node.js, the web container execution environment does not currently support passing transferable objects via `receiveMessageOnPort`. Attempting to do so will cause a serialization error and a failed application build. To avoid this problem, the wait loop optimization is disabled when the web container execution environment is detected. This change is only needed for the TS/NG compilation as no other parallel operation within the build system currently uses `receiveMessageOnPort` with transferable objects. (cherry picked from commit 6f9ef1fbb147f7d8f25d48500595b3f92ebb9ba2) --- .../tools/esbuild/angular/compilation/parallel-compilation.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/parallel-compilation.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/parallel-compilation.ts index b23ed97d0fca..0da2a186956f 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/parallel-compilation.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compilation/parallel-compilation.ts @@ -36,6 +36,9 @@ export class ParallelCompilation extends AngularCompilation { minThreads: 1, maxThreads: 1, idleTimeout: Infinity, + // Web containers do not support transferable objects with receiveOnMessagePort which + // is used when the Atomics based wait loop is enable. + useAtomics: !process.versions.webcontainer, filename: localRequire.resolve('./parallel-worker'), }); }