Repository navigation
Closed
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrations
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
Every time I execute the ng generate @angular/core:cleanup-unused-imports schematic on my project, I get a "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory"
Is it possible to add a parameter to make it run on a folder level like the control flow schematic?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Preparing analysis for projects/first-app/tsconfig.app.json
Preparing analysis for projects/first-lib/tsconfig.lib.json
Preparing analysis for projects/first-lib/tsconfig.lib.prod.json
Preparing analysis for projects/shared-lib/tsconfig.lib.json
Preparing analysis for projects/shared-lib/tsconfig.lib.prod.json
Preparing analysis for projects/second-app-cockpit/tsconfig.app.json
Preparing analysis for projects/second-app-shared-lib/tsconfig.lib.prod.json
Preparing analysis for projects/second-app-shared-lib/tsconfig.lib.json
Preparing analysis for projects/second-app-dashboard/tsconfig.app.json
Preparing analysis for projects/third-app-cockpit/tsconfig.app.json
Preparing analysis for projects/third-app-shared-lib/tsconfig.lib.prod.json
Preparing analysis for projects/third-app-shared-lib/tsconfig.lib.json
Preparing analysis for projects/fourth-app-cockpit/tsconfig.app.json
Preparing analysis for projects/fourth-app-shared-lib/tsconfig.lib.prod.json
Preparing analysis for projects/fourth-app-shared-lib/tsconfig.lib.json
Preparing analysis for projects/first-app/tsconfig.spec.json
<--- Last few GCs --->
[13008:000001AA4F9FC0B0] 204999 ms: Mark-Compact 4051.8 (4141.3) -> 4037.2 (4142.5) MB, 1323.39 / 0.00 ms (average mu = 0.236, current mu = 0.125) allocation failure; scavenge might not succeed
[13008:000001AA4F9FC0B0] 207571 ms: Mark-Compact 4055.6 (4145.1) -> 4043.1 (4148.1) MB, 2470.53 / 0.00 ms (average mu = 0.123, current mu = 0.039) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF63B18413F node::SetCppgcReference+15695
2: 00007FF63B0FEA56 EVP_MD_meth_get_input_blocksize+78566
3: 00007FF63B100841 EVP_MD_meth_get_input_blocksize+86225
4: 00007FF63BB6A5E1 v8::Isolate::ReportExternalAllocationLimitReached+65
5: 00007FF63BB53D78 v8::Function::Experimental_IsNopFunction+1336
6: 00007FF63B9B55E0 v8::Platform::SystemClockTimeMillis+659552
7: 00007FF63B9B2668 v8::Platform::SystemClockTimeMillis+647400
8: 00007FF63B9C797A v8::Platform::SystemClockTimeMillis+734202
9: 00007FF63B9C81F7 v8::Platform::SystemClockTimeMillis+736375
10: 00007FF63B9D6B1F v8::Platform::SystemClockTimeMillis+796063
11: 00007FF63B6970E5 v8::CodeEvent::GetFunctionName+116773
12: 00007FF5DBBDAAFA
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 19.1.5
Node: 22.13.0
Package Manager: npm 11.0.0
OS: win32 x64
Angular: 19.1.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1901.5
@angular-devkit/build-angular 19.1.5
@angular-devkit/core 19.1.5
@angular-devkit/schematics 19.1.5
@angular/cdk 19.1.2
@angular/cli 19.1.5
@schematics/angular 19.1.5
ng-packagr 19.1.2
rxjs 7.8.1
typescript 5.7.3
zone.js 0.15.0
Anything else?
No response
Reacted by Nam Pham, Michael Small, ( Nechiforel David-Samuel ) NsdHSO , Wojtek Szydlak, Julien Saguet, Timur Mishagin, Michael Andorfer, helix46, Mathias Hellsing, Travis Simon and 6 more
Reacted by stianmorsund and Max Sh
Metadata
Metadata
Assignees
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrations
Activity
KhoaNam225 commentedon Jan 31, 2025
Upvote as I'm also having this issue
msmallest commentedon Jan 31, 2025
This error seems applicable to more migrations, but I'll go into detail about this imports one in a moment.
I just tried
ng generate @angular/core:signal-input-migrationscoped to a single folder but since the schematic still reads all thetsconfigs in a project it ran out of memory in a big workspace monorepo at about 20 "Preparing analysis for:" steps. This seems on point with my testing of this particular issue's schematics for unused importsI tested the unused imports schematic. The bottleneck seems to definitely be the "Preparing"
tsconfig.xyz.jsonsteps.I stress tested this with a repro with 20 applications (10 SPA, 10 SSR) aka 42 configs with the apps + test + 2 root ones. Freshly generated apps with no modifications. https://github.com/michael-small/test-cleanup-unused/tree/20-apps. On my WSL installation on the latest versions(edit: I guess it was 19.1, but the same type of errors in this applied in my latest versions projects), my particular specs gave up on the 29th prepare step consistently.edit: I made a repro with 10 SPA and 20 SSR fresh apps with the actual latest versions. Dropping the
ng versionin the README to save space on this page lol. I stress tested this with a repro with 30 applications (10 SPA, 20 SSR) aka 62 configs with teh apps + test + 2 root ones. Fresh apps. My smaller repro blew over at around 29 prepare steps consistently and my macbook in this repro failed around 57 in.I know that number surely varies with specs, but the consistent thing is I noticed the slowdown near my memory threshhold is during the "preparing" steps. However, if the CLI can manage all of those and get a couple of "Scanning" steps, then it could consistently finish with no memory issues. And anything under my particular out of memory threshold with prepare steps seemed to consistently pass.
Generating more repos by +1ing the project name and then removing their entry in the
angular.jsonin my opinion is a good repro benchmarking for this bug.t-mish commentedon Feb 3, 2025
Upvote
MAN-Sendance commentedon Feb 4, 2025
This behavior is also encountered for
@angular/core:output-migrationand@angular/core:signal-queries-migrationand@angular/core:cleanup-unused-imports, impacting any process that requires extensive preparation.BenLune commentedon Feb 17, 2025
I also have the same problem. I thought the problem was on my side in webstorm settings or something like that, but it doesn't seem to be the cause.
oliverdrummond commentedon Mar 4, 2025
Same still happens with Angular 19.2.0
devversion commentedon Mar 17, 2025
Hey all, just discovered this issue and would like to help.
node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng?chrisczach commentedon Mar 17, 2025
I work on a pretty large angular project with several apps built from the same codebase and ended up having to do this to get some migrations to run.
Set the heap size in the terminal.
export NODE_OPTIONS=--max_old_space_size=16384Then start running the problematic migrations.
oliverdrummond commentedon Mar 18, 2025
Thanks! @devversion and @chrisczach . Just tried it with
export NODE_OPTIONS=--max_old_space_size=16384and it worked!jkyoutsey commentedon Mar 19, 2025
I have a huge Nx repo. I have 200+ libs. Even set to 24GB I can't get this to work.
I get past the Preparing phase and into the Scanning phase
devversion commentedon Mar 19, 2025
@jkyoutsey were you able to run migrations in the past? or did you also occasionally have trouble with those?
are you only running the cleanup unused imports migrations?
jkyoutsey commentedon Mar 20, 2025
@devversion Other migrations run fine. It's just this one that runs out of memory. It's a big Nx repo. It would be nice if it allowed us to run this on a subset of the repo at a time. Or just didn't run out of memory 😄
devversion commentedon Mar 20, 2025
Thx @jkyoutsey for the information. If you still remember, would be good to hear which migration worked in the past.
There is a subtle difference between AST simpler migrations, and type-based migrations needing a full Angular compiler instance running. I will try looking into this a bit.
jmeinlschmidt commentedon Mar 31, 2025
upvote
fix(core): reduce total memory usage of various migration schematics
JoostK commentedon Apr 7, 2025
I think I have a fix for this in #60774. It chooses a different trade-off w.r.t. run time versus memory usage, considering that memory usage has revealed to cause OOM crashes.
For "complex" migrations (signal-inputs and signal-queries) this change does introduce overhead in the form of having to create the TypeScript program for all entrypoints (i.e. tsconfig paths) twice, but the reduced memory pressure is expected to reduce garbage collection overhead. I don't have a feeling for the overall impact on execution time, but the reduced memory usage should allow the migration to run to completion instead of crashing.
fix(core): reduce total memory usage of various migration schematics
fix(core): reduce total memory usage of various migration schematics (a…
fix(core): reduce total memory usage of various migration schematics (#…
angular-automatic-lock-bot commentedon May 8, 2025
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.