aside icon indicating copy to clipboard operation
aside copied to clipboard

Angular build fails with malloc error on second build

Open YukiFujisawa opened this issue 1 year ago • 2 comments

Angular build fails with malloc error on second build

Description

When running the Angular build command twice in succession, the second build fails with a malloc error. The first build completes successfully, but subsequent builds fail with a memory-related error.

Environment

Angular CLI: 19.0.5
Node: 20.18.1
Package Manager: npm 10.8.2
OS: darwin arm64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.5
@angular-devkit/build-angular   19.0.5
@angular-devkit/core           19.0.5
@angular-devkit/schematics     19.0.5
@angular/cdk                   19.0.3
@angular/cli                   19.0.5
@angular/material              19.0.3
@schematics/angular           19.0.5
rxjs                          7.8.1
typescript                    5.6.3
zone.js                       0.15.0

Error Message

node(71866,0x20647cf40) malloc: *** error for object 0x3bb90e420460: pointer being freed was not allocated
node(71866,0x20647cf40) malloc: *** set a breakpoint in malloc_error_break to debug
sh: line 1: 71816 Abort trap: 6           npm run build-ui

Steps to Reproduce

  1. Run first build command: npm run deploy
    • Result: Build succeeds
  2. Run second build command: npm run deploy
    • Result: Build fails with malloc error

Proposed Solutions

Solution 1: Clear Angular CLI Cache

Running ng cache clean resolves the issue.

Solution 2: Add Clean Step to Build Process

Adding a clean step to the build-ui script in package.json:

{
  "scripts": {
    "build-ui": "npm run clean --prefix src/ui && npm run build --prefix src/ui"
  }
}

Additional Context

The error appears to be related to Angular CLI's cache management. Either clearing the cache manually or implementing an automatic clean step before builds prevents the malloc error from occurring.

Questions

  • Are these solutions effective for all environments and Angular versions?
  • Is there a more fundamental solution that addresses the root cause of the malloc error?
  • Could this be related to a specific version of the Angular CLI or Node.js?

YukiFujisawa avatar Dec 15 '24 00:12 YukiFujisawa

Hey, i just fixed the problem myself.

The cause of the issue is the license-check-and-add plugin was adding license header to angular build cache. You need to exclude the path in license-config.json.

You can refer to https://github.com/HaoYuan90/doc_review/commit/a092f5c9ba50479b28fa8ef3a9c06038a1d4fe07

Do note my personal project's path structure is slightly different from what is bootstrapped by aside out of the box. I will raise PR to fix the problem if project maintainer allows :)

And dont forget to clean the cache folder after the license config change is made.

HaoYuan90 avatar May 06 '25 07:05 HaoYuan90

@victor-paunescu PTAL, the fix is simple as adding a line "src/ui/.angular" to license-config.json. I dont have permissions to make the change myself 🙇

HaoYuan90 avatar May 06 '25 08:05 HaoYuan90