Skip to content

[Bug]: "contents" must be a string or a Uint8Array during ng build #33841

Closed as not planned

Description

@Bywdl

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

compiler-cli, compiler

Is this a regression?

Yes

Description

When building a completely clean, freshly generated Angular 22 project (ng new with SSR enabled), the production build (ng build) fails consistently with a "contents" must be a string or a Uint8Array error.

The project is completely pristine with no custom configurations or other third-party packages.

Key Observations:

  1. SSR Dependency: The error only occurs when Server-Side Rendering (SSR) is enabled during project generation. If I create the exact same clean project without SSR, the build succeeds.
  2. Dev Server Works: The development server (ng serve) works perfectly without any issues; it only crashes during ng build.
  3. Vite 8 / Rolldown Context: In earlier Angular 22 versions using Vite 7 (Rollup), this was not an issue. This freshly generated project uses the newer Vite 8 with the Rolldown bundler. It appears the angular-compiler plugin in esbuild fails to resolve or load these specific UI library modules during the SSR/prerendering build phase under this new architecture.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

✘ [ERROR] "contents" must be a string or a Uint8Array [plugin angular-compiler]

    node_modules/esbuild/lib/main.js:534:29:
      534 │   if (mustBe !== null) throw new Error(`${quote(key)} must be ${m...
          ╵                                ^

    at getFlag (<workspace>/node_modules/esbuild/lib/main.js:534:30)
    at requestCallbacks.on-load (<workspace>/node_modules/esbuild/lib/main.js:1559:26)
    at async handleRequest (<workspace>/node_modules/esbuild/lib/main.js:909:11)

  This error came from the "onLoad" callback registered here:

    node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:18:
      397 │             build.onLoad({ filter: /\.[cm]?js$/ }, (0, load_resul...
          ╵                   ~~~~~~

    at setup (<workspace>/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:19)
    at async handlePlugins (<workspace>/node_modules/esbuild/lib/main.js:1466:20)

  The plugin "angular-compiler" was triggered by this import

    src/app/shared/components/bs-reuse-tab/reuse-tab-context.service.ts:2:32:
      2 │ import { ComponentPortal } from '@angular/cdk/portal';
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] "contents" must be a string or a Uint8Array [plugin angular-compiler]

    node_modules/esbuild/lib/main.js:534:29:
      534 │   if (mustBe !== null) throw new Error(`${quote(key)} must be ${m...
          ╵                                ^

    at getFlag (<workspace>/node_modules/esbuild/lib/main.js:534:30)
    at requestCallbacks.on-load (<workspace>/node_modules/esbuild/lib/main.js:1559:26)
    at async handleRequest (<workspace>/node_modules/esbuild/lib/main.js:909:11)

  This error came from the "onLoad" callback registered here:

    node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:18:
      397 │             build.onLoad({ filter: /\.[cm]?js$/ }, (0, load_resul...
          ╵                   ~~~~~~

    at setup (<workspace>/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:19)
    at async handlePlugins (<workspace>/node_modules/esbuild/lib/main.js:1466:20)

  The plugin "angular-compiler" was triggered by this import

    src/app/shared/components/bs-reuse-tab/reuse-tab.component.ts:7:48:
      7 │ import { NzTabComponent, NzTabsComponent } from 'ng-zorro-antd/tabs';
        ╵                                                  ~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] "contents" must be a string or a Uint8Array [plugin angular-compiler]

    node_modules/esbuild/lib/main.js:534:29:
      534 │   if (mustBe !== null) throw new Error(`${quote(key)} must be ${m...
          ╵                                ^

    at getFlag (<workspace>/node_modules/esbuild/lib/main.js:534:30)
    at requestCallbacks.on-load (<workspace>/node_modules/esbuild/lib/main.js:1559:26)
    at async handleRequest (<workspace>/node_modules/esbuild/lib/main.js:909:11)

Please provide the environment you discovered this bug in (run ng version)

**Environment:**
Angular CLI       : 22.1.3
Node.js           : 24.16.0
Package Manager   : npm 11.13.0
Operating System  : linux x64 (KylinOS, Kernel: 5.4.18.63-generic x86_64)

Anything else?

No response

Activity

  1. added
    gemini-triaged
    on Aug 12, 2026
  2. added this to the needsTriage milestone on Aug 12, 2026
  3. added this to the needsTriage milestone on Aug 12, 2026
  4. transferred this issue fromangular/angularon Aug 12, 2026
  5. alan-agius4 commented on Aug 13, 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.

  6. added
    needs: repro steps
    on Aug 13, 2026
  7. imthiyazhassan commented on Aug 13, 2026

    @imthiyazhassan

    I get the same error consistently on my Azure DevOps Linux agent, but works fine locally on my dev Windows machine. Issue started happening after I upgraded Angular from 21.2.19 to 22.1.4, and NodeJS from 22.13.1 to 24.19.0.

    I do not have SSR enabled.

    ✘ [ERROR] "contents" must be a string or a Uint8Array [plugin angular-compiler]
    
      node_modules/esbuild/lib/main.js:534:29:
        534 │   if (mustBe !== null) throw new Error(`${quote(key)} must be ${m...
            ╵                              ^
    
      at getFlag (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:534:30)
      at requestCallbacks.on-load (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:1563:26)
      at async handleRequest (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:911:11)
    
    This error came from the "onLoad" callback registered here:
    
      node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:18:
        397 │             build.onLoad({ filter: /\.[cm]?js$/ }, (0, load_resul...
            ╵                   ~~~~~~
    
      at setup (/v/w/4/s/Source/UI/IPA/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:19)
      at async handlePlugins (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:1470:20)
    
    The plugin "angular-compiler" was triggered by this import
    
      node_modules/lodash-es/lodash.js:276:34:
        276 │ export { default as toJSON } from './toJSON.js';
            ╵                                   ~~~~~~~~~~~~~
    
    
  8. Bywdl commented on Aug 14, 2026

    @Bywdl
    Author

    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.你可以在这里阅读有关为何需要这样做的原因。要尽可能简单地重现问题,可以创建一个新的应用程序,并添加尽可能少的代码来展示问题。之后,你可以将这个仓库推送到 GitHub 上,并在此处附上链接。

    This might be related to your directory structure so its really important to get an accurate repro to diagnose this.这可能与你的目录结构有关,因此获取准确的复制件对于诊断问题非常重要。

    I apologize, but I cannot provide a minimal reproduction repository because this is happening on a company-issued machine that does not allow external network access (an isolated environment).

    However, I can provide the exact steps to reproduce it. Interestingly, you don't even need to install ng-zorro-antd or any third-party UI libraries to trigger this issue. A completely clean, out-of-the-box project created via ng new will throw this error.

    Here are the reproduction steps:

    Environment:

    Angular CLI : 22.1.3

    Node.js : 24.16.0

    Package Manager : npm 11.13.0

    Operating System : linux x64 (KylinOS, Kernel: 5.4.18.63-generic x86_64)

    Create a New Project:
    Run ng new to create a fresh project, and make sure to enable SSR during the prompt options.

    Build the Project:
    Navigate into the project directory and run npm run build (or ng build). Shortly after, the "contents" must be a string or a Uint8Array build error will occur.

    I hope these steps help you locate and reproduce the issue on your end without needing a GitHub repository!

  9. Bywdl commented on Aug 14, 2026

    @Bywdl
    Author

    I get the same error consistently on my Azure DevOps Linux agent, but works fine locally on my dev Windows machine. Issue started happening after I upgraded Angular from 21.2.19 to 22.1.4, and NodeJS from 22.13.1 to 24.19.0.

    I do not have SSR enabled.

    ✘ [ERROR] "contents" must be a string or a Uint8Array [plugin angular-compiler]
    
      node_modules/esbuild/lib/main.js:534:29:
        534 │   if (mustBe !== null) throw new Error(`${quote(key)} must be ${m...
            ╵                              ^
    
      at getFlag (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:534:30)
      at requestCallbacks.on-load (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:1563:26)
      at async handleRequest (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:911:11)
    
    This error came from the "onLoad" callback registered here:
    
      node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:18:
        397 │             build.onLoad({ filter: /\.[cm]?js$/ }, (0, load_resul...
            ╵                   ~~~~~~
    
      at setup (/v/w/4/s/Source/UI/IPA/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:397:19)
      at async handlePlugins (/v/w/4/s/Source/UI/IPA/node_modules/esbuild/lib/main.js:1470:20)
    
    The plugin "angular-compiler" was triggered by this import
    
      node_modules/lodash-es/lodash.js:276:34:
        276 │ export { default as toJSON } from './toJSON.js';
            ╵                                   ~~~~~~~~~~~~~
    

    Thanks for jumping in, @imthiyazhassan ! This is a massive clue.

    Since it fails on your Azure DevOps Linux agent but works on Windows, and my environment is also Linux (KylinOS), we can safely rule out SSR and third-party libraries as the root cause.

    It strongly points to a platform-specific issue with Linux + Node 24.x + Angular 22.1.x (esbuild/Vite 8 pipeline). It seems esbuild or the underlying file system reads return undefined/null instead of a Buffer/String under this specific combination.

    To summarize for the Angular team, here is the failure matrix based on both of our reports:

    Fails: Linux (KylinOS) + Node 24.16.0 + Angular 22.1.3 (My environment)

    Fails: Linux (Azure DevOps) + Node 24.19.0 + Angular 22.1.4 (Your environment)

    Works: Windows + Node 24.19.0 + Angular 22.1.4 (Your local dev environment)

    @alan-agius4 - Could this be an issue with how esbuild/Vite 8 interacts with the Linux file system API in Node 24? This explains why it might be harder to reproduce on macOS/Windows dev machines.

    @imthiyazhassan , since the Angular team usually requires standard environment details, could you run ng version on your Azure DevOps Linux agent and share the full output here?

    This will automatically include your exact Linux distribution and architecture alongside your Node and Angular versions. Having that complete log will be super helpful to compare against my KylinOS environment and help the team pinpoint the issue!

  10. imthiyazhassan commented on Aug 14, 2026

    @imthiyazhassan

    Our build agents are on Ubuntu 20.04.6. Here is the output of ng version:

    Angular CLI       : 22.1.4
    Angular           : 22.1.2
    Node.js           : 24.19.0
    Package Manager   : npm 11.17.0
    Operating System  : linux x64
    
    ┌───────────────────────────────────┬───────────────────┬───────────────────┐
    │ Package                           │ Installed Version │ Requested Version │
    ├───────────────────────────────────┼───────────────────┼───────────────────┤
    │ @angular/animations               │ 22.1.2            │ 22.1.2            │
    │ @angular/build                    │ 22.1.4            │ 22.1.4            │
    │ @angular/cdk                      │ 22.1.2            │ 22.1.2            │
    │ @angular/cli                      │ 22.1.4            │ 22.1.4            │
    │ @angular/common                   │ 22.1.2            │ 22.1.2            │
    │ @angular/compiler                 │ 22.1.2            │ 22.1.2            │
    │ @angular/compiler-cli             │ 22.1.2            │ 22.1.2            │
    │ @angular/core                     │ 22.1.2            │ 22.1.2            │
    │ @angular/forms                    │ 22.1.2            │ 22.1.2            │
    │ @angular/language-service         │ 22.1.2            │ 22.1.2            │
    │ @angular/material                 │ 22.1.2            │ 22.1.2            │
    │ @angular/material-luxon-adapter   │ 22.1.2            │ 22.1.2            │
    │ @angular/platform-browser         │ 22.1.2            │ 22.1.2            │
    │ @angular/platform-browser-dynamic │ 22.1.2            │ 22.1.2            │
    │ @angular/router                   │ 22.1.2            │ 22.1.2            │
    │ ng-packagr                        │ 22.1.1            │ 22.1.1            │
    │ rxjs                              │ 7.8.2             │ 7.8.2             │
    │ typescript                        │ 6.0.3             │ 6.0.3             │
    │ vitest                            │ 4.1.10            │ 4.1.10            │
    │ zone.js                           │ 0.16.2            │ 0.16.2            │
    └───────────────────────────────────┴───────────────────┴───────────────────┘
    
    
  11. alan-agius4 commented on Aug 14, 2026

    @alan-agius4
    Collaborator

    Unfortunately, without a minimal reproduction, we aren't able to investigate this further. Most of our development and testing takes place on Linux, where we haven't been able to replicate the issue. If you can provide a minimal reproduction steps or code sample, we’d be happy to take another look.

  12. Bywdl commented on Aug 14, 2026

    @Bywdl
    Author

    Unfortunately, without a minimal reproduction, we aren't able to investigate this further. Most of our development and testing takes place on Linux, where we haven't been able to replicate the issue. If you can provide a minimal reproduction steps or code sample, we’d be happy to take another look.

    Here are the reproduction steps:

    Environment:

    Angular CLI : 22.1.3

    Node.js : 24.16.0

    Package Manager : npm 11.13.0

    Operating System : linux x64 (KylinOS, Kernel: 5.4.18.63-generic x86_64)

    Create a New Project:
    Run ng new to create a fresh project, and make sure to enable SSR during the prompt options.

    Build the Project:
    Navigate into the project directory and run npm run build (or ng build). Shortly after, the "contents" must be a string or a Uint8Array build error will occur.

  13. alan-agius4 commented on Aug 14, 2026

    @alan-agius4
    Collaborator

    @Bywdl/@imthiyazhassan please provide a runnable reproduction, without it we cannot look into this.

    We are able to build successfully an ng new application on Linux and Windows using Node.js 22.22.3, 24.15.0 and 26.0.0.

    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.

  14. Bywdl commented on Aug 14, 2026

    @Bywdl
    Author

    @Bywdl/@imthiyazhassan please provide a runnable reproduction, without it we cannot look into this.

    We are able to build successfully an ng new application on Linux and Windows using Node.js 22.22.3, 24.15.0 and 26.0.0.

    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.

    I completely understand that a minimal reproduction repository is the standard procedure. However, as I mentioned, there is zero custom code to provide. The "minimal repro code" is literally just running ng new repro-app and then ng build. That is the entire codebase.

    Since your team develops and tests on Linux without issues, I strongly suspect this is a system-level compatibility bug (likely related to glibc or the file system API) between Node 24.x, the new esbuild/Rolldown compiler, and specific Linux kernels.

    Here are two crucial clues that might help your team replicate this:

    Kernel Version Difference: Your testing environments likely use modern Linux kernels (e.g., 5.15+ or 6.x on Ubuntu 22.04/24.04). My KylinOS is running an older kernel (5.4.18.63).

    Azure DevOps Environment: As another user mentioned in this thread, they are encountering the exact same contents must be a string or a Uint8Array error on an Azure DevOps Linux agent with Node 24.19.0.

    Suggested Repro Steps for the Team:
    Instead of a code repository, could you please try reproducing this by:

    Spinning up a Docker container with an older Linux image (such as Ubuntu 20.04, which runs on a 5.4 kernel).

    Or running a quick ng new -> ng build test via an Azure DevOps Linux pipeline with Node 24.16+ and Angular 22.1.3+.

    This is definitely a real platform-specific bug affecting enterprise/CI Linux environments, not a user-code error. We would really appreciate it if you could take a second look from the environment perspective!

  15. imthiyazhassan commented on Aug 14, 2026

    @imthiyazhassan

    We upgraded our build agents to Ubuntu v24.04 and that resolved the issue.

  16. manInit commented on Aug 27, 2026

    @manInit
    Contributor

    This is reproducible, but the trigger is not the kernel or the distro itself — it is the persistent cache store fallback, which is why it could not be reproduced here.

    createPersistentCacheStore() tries LMDB first and silently falls back to the built-in SQLite store on any load failure. On Ubuntu 20.04 the prebuilt @lmdb/lmdb-linux-x64@3.5.6 binary requires GLIBC_2.33 while the host provides glibc 2.31, so the fallback kicks in. Debian 11 and RHEL/CentOS 8 ship the same glibc. Upgrading the agent to Ubuntu 24.04 "fixes" it only because LMDB loads again there and the SQLite store is no longer used.

    The SQLite store persists values with JSON.stringify and reads them back with JSON.parse. Some cached values are binary — JavaScriptTransformer is constructed with Cache<Uint8Array>, and CachedLoadResultEntry.contents is typed string | Uint8Array — and a JSON round trip cannot represent a typed array. A real row from .angular/cache/22.1.5/<project>/angular-compiler-sqlite.db:

    key:   jstransformer:000e84ece3a6f3f24cd37f3c37b7f8e94942ee88c0b1dd1cfc660e5c3fd71b07
    value: {"0":105,"1":109,"2":112,"3":111,"4":114,"5":116,…}
    

    That plain object is then returned from the onLoad callback in angular/compiler-plugin.ts as contents, which produces the error. It only appears from the second build onwards, because the first build serves the value from the in-memory cache layer — the value is corrupted only once it has been read back from disk.

    Machine-independent reproduction, forcing the store through the existing environment option:

    rm -rf .angular
    NG_BUILD_CACHE_STORE=sqlite ng build   # ok
    NG_BUILD_CACHE_STORE=sqlite ng build   # ✘ "contents" must be a string or a Uint8Array

    On a machine where LMDB loads normally, the broken store is never reached, so ng new + ng build will not show it without that variable.

    Fix in #33947 — the store now serializes with the V8 structured clone API, which supports typed arrays natively and matches the LMDB store's behavior.

  17. added a commit that references this issue on Aug 27, 2026
    2954209
  18. added 2 commits that reference this issue on Aug 27, 2026
    135662d
    fcf883e
  19. angular-automatic-lock-bot commented on Oct 20, 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.

  20. locked and limited conversation to collaborators on Oct 20, 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

    area: @angular/buildgemini-triagedneeds: repro steps

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions