Skip to content

advancedOptimizations (oxc-transform) corrupts vendor bundle output — related to #33699, but fix in #33700 doesn't fully resolve it, and worker pool concurrency setting also implicated #33973

Closed

Description

@Mailman-afk

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

Unconfirmed - likely any version prior to the oxc-transform.js rewrite introduced around 22.1.0 (same regression window as #33699).

Description

This is related to #33699, fixed by #33700, but appears to be a broader/different bug that isn't fully resolved by that fix.

src/tools/babel/plugins/oxc-transform.js performs single-pass AST-based source rewriting via oxc-parser + magic-string, wrapping TypeScript-emitted enums (adjustTypeScriptEnumsInStatements) and Angular/class static members (adjustStaticMembersInStatements) into pure IIFEs for tree-shaking. #33699 found an appendLeft/appendRight ordering bug in the latter function for adjacent minified classes, fixed by swapping the insertion order in #33700.

I hit a similar-looking corruption (Unexpected "}" at the closing })(); of a wrapped statement) in two unrelated vendor files consistently, on every build, but only on our GitLab CI's native x86_64 Docker runners - never locally (Apple Silicon via Rosetta-emulated x86_64 Docker, using the byte-for-byte identical image/lockfile/node_modules, verified via SHA-256 checksum).

I bisected my own working fix down via bun patch on @angular/build@22.1.6 (which already includes the #33700 fix) and found:

  1. Disabling both adjustTypeScriptEnumsInStatements and adjustStaticMembersInStatements (short-circuiting each to a no-op) + forcing atomics: 'disabled' in src/utils/worker-pool.js's Piscina options (instead of the default 'sync') → build passes reliably.
  2. Re-enabling only adjustStaticMembersInStatements (leaving the enum function disabled, atomics still disabled) → build fails again, even though this function already contains the fix(@angular/build): prevent IIFE wrapper interleaving for adjacent classes in minified files #33700 fix (confirmed: the installed 22.1.6 source has the appendRight(classNode.start, ...)/appendLeft(lastStatement.end, ...) ordering from that PR). This suggests fix(@angular/build): prevent IIFE wrapper interleaving for adjacent classes in minified files #33700 does not cover every code path in this function - possibly the __decorate-wrapping or elision branches, which weren't touched by that PR's diff.
  3. Removing only the atomics: 'disabled' change (keeping both functions disabled) → build fails again. This was surprising since we assumed the text-splicing bug should be purely deterministic/input-dependent, unrelated to worker thread synchronization. This suggests either a genuine concurrency element (e.g. stale/cross-contaminated state between files processed by the same reused worker thread, only exposed under certain Atomics.wait/futex timing), or that the 'sync' atomics mode itself interacts with the native oxc-parser binding in a way that produces incorrect AST offsets under specific scheduling conditions.

I am not able to fully isolate a single minimal cause - only the combination of all three changes together reliably fixes it. I was also unable to produce a minimal public repro (a fresh ng new + npm i quill@2.0.3 did not reproduce it standalone, even on the failing CI environment) - my repro requires my full app (which includes a private package, and quill), built on a real native x86_64 GitLab CI Docker runner.

Minimal Reproduction

Not available as a minimal public repro (see above). Happy to test candidate fixes/diagnostics against our real CI pipeline, since I can reproduce this with 100% reliability there.

Failing file/line (consistent across every run):

  • node_modules/parchment/dist/parchment.js:86:0

Third-party pre-built ESM/CJS bundles consistent with #33699's observation that this only affects pre-built vendor code (Angular's own non-minified fesm2022 packages are unaffected).

Exception or Error

✘ [ERROR] Unexpected "}"

    node_modules/parchment/dist/parchment.js:86:0:
      86 │ })();
         ╵ ^

Your Environment

Angular CLI: 22.1.6
@angular/build: 22.1.6
@angular/core: 22.1.4
oxc-parser: 0.142.0
rolldown: 1.2.0
piscina: 5.2.0

Package Manager: bun 1.4.0

OS (failing, 100% reproducible): Alpine Linux 3.23, linux/x86_64, native (confirmed no QEMU/binfmt emulation, `cgroup cpu.max`: unlimited, `memory.max`: 32GiB)
OS (never fails): macOS (Apple Silicon, arm64), Docker Desktop, linux/amd64 image run via Rosetta 2 emulation

Angular: 22.1.4 (ivy)

Anything else relevant?

My current working mitigation (applied via bun patch), for reference:

for (...) { ... }
return; // disabled
for (...) { ... }
@@ function adjustStaticMembersInStatements(body) {
for (...) { ... }
return; // disabled
for (...) { ... }
--- a/src/utils/worker-pool.js +++ b/src/utils/worker-pool.js
atomics: process.versions.webcontainer ? 'disabled' : 'sync',
atomics: 'disabled', ```
This trades away some tree-shaking of enums/class-statics for the vendor files I ship, but restores a reliable production build. I'd very much like a proper fix so we can re-enable full advancedOptimizations.

This version is honest about the fact that I couldn't cleanly isolate a single cause — which is itself useful signal (it points toward either an incomplete fix in #33700, or a genuine worker-concurrency interaction, rather than a simple one-line bug). Want me to also open a note in my own repo (e.g. a KNOWN_ISSUES.md or a comment near the patch file) documenting this so future maintainers understand why the patch exists and when it might be safe to remove?

Activity

  1. added this to the needsTriage milestone on Aug 31, 2026
  2. alan-agius4 commented on Aug 31, 2026

    @alan-agius4
    Collaborator

    Can you try using @angular/build version 22.2.0-next.5?

  3. Mailman-afk commented on Sep 2, 2026

    @Mailman-afk
    Author

    22.2.0-next.5 does not solve this

  4. alan-agius4 commented on Sep 2, 2026

    @alan-agius4
    Collaborator

    This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

    You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

    This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

  5. added
    needs: repro stepsWe cannot reproduce the issue with the information given
    and removed on Sep 2, 2026
  6. Mailman-afk commented on Sep 2, 2026

    @Mailman-afk
    Author

    I managed to build a minimal, public reproduction: https://github.com/Mailman-afk/oxc-transform-repro

    TL;DR

    The missing variable was musl libc (Alpine), not glibc. A fresh ng new app depending only on quill + quill-mention (2 lazy chunks via @defer) reproduces the exact same

    ✘ [ERROR] Unexpected "}"
        node_modules/parchment/dist/parchment.js:86:0:
          86 │ })();
             ╵ ^
    

    100% of the time (6/6 CI runs), when the production build (ng build) is run inside an alpine:3.23 container on a native x86_64 host - but never on a plain glibc-based Linux host with the identical dependencies/Node/Bun versions.

    What I tried before landing on this

    • Scoping the dependencies back down to just quill/quill-mention (2 chunks) under the same Alpine container: still fails 100% of the time. So it's not about chunk count/worker-pool stress at all - musl libc alone is sufficient.
    • Confirmed this does not reproduce under any form of x86_64 emulation (Rosetta 2 on Apple Silicon, or Docker/QEMU --platform linux/amd64 on Apple Silicon), even inside the same Alpine 3.23 container - it requires native x86_64 execution.

    Reproduction environment

    • GitHub Actions ubuntu-latest runner (native x86_64, no QEMU emulation)
    • Job runs inside container: image: alpine:3.23 (musl libc)
    • Bun 1.4.0 installed via the same method as our production CI image
    • @angular/cli / @angular/build 22.1.6, @angular/core 22.1.4

    How to reproduce

    1. Fork/clone https://github.com/Mailman-afk/oxc-transform-repro
    2. Push to trigger the "Reproduce oxc-transform corruption" GitHub Actions workflow (or trigger manually via "Run workflow")
    3. Or run locally inside an alpine:3.23 container on a native x86_64 Linux host:
      apk add --no-cache git gcompat libstdc++ bash curl unzip
      curl -fsSL https://bun.com/install | bash
      export PATH="$HOME/.bun/bin:$PATH"
      bun install --frozen-lockfile
      bun run build

    Happy to add any additional diagnostics/instrumentation to the repro if useful - this one's been a rabbit hole, but musl libc + native x86_64 now looks like a solid, minimal, deterministic reproduction case.

  7. alan-agius4 commented on Sep 3, 2026

    @alan-agius4
    Collaborator

    Thank you for reporting this and providing the minimal reproduction repository.

    After investigating using the reproduction environment, this was traced down to an upstream bug in Bun's parser/transpiler, rather than an issue in the Angular build pipeline, transformation logic, or worker concurrency.

    Root Cause

    In oxc-transform, a single-line comment was describing the variable class wrapping pattern:

    // Wrap class inside init: `/*#__PURE__*/ (() => { let ClassName = class ClassName {}; return ClassName; })()`
    source.appendRight(classNode.start, `/*#__PURE__*/ (() => {\nlet ${classIdName} = `);

    When Bun executes this code:

    1. Comment Scanner Leak: Bun's lexer matches /*#__PURE__*/ even when it is embedded within a single-line // comment.
    2. Incorrect Pure Annotation & Dead Code Elimination (DCE): Bun erroneously treats the following statement (source.appendRight(...)) as a pure call (/*#__PURE__*/ source.appendRight(...)). Because its return value is discarded in an expression statement, Bun's DCE treats the call as having no side effects and completely strips source.appendRight(...) from the executed code.
    3. Mismatched Closer: The subsequent source.appendLeft(lastStatement.end, ...) call still executes. When transforming files like parchment.js that contain a variable class expression (const _Registry = class _Registry { ... };), the closing \nreturn _Registry;\n})(); is appended, but the opening wrapper was never inserted. This leaves a dangling })(); that causes esbuild to fail with Unexpected "}".

    Minimal Bun Reproduction

    You can reproduce this behavior in Bun in isolation:

    bun -e '
    function repro() {
        // `/*#__PURE__*/`
        console.log("This will be deleted by Bun");
    }
    console.log(repro.toString());
    '

    Output in Bun (v1.4.0):

    function repro() {}

    In Node.js / V8, comments are properly treated as trivia and the statement is not eliminated.

    Mitigation & Fix

  8. added 2 commits that reference this issue on Sep 3, 2026
    fae77b9
    675f1f5
  9. angular-automatic-lock-bot commented on Oct 21, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions