nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.97k stars 2.3k forks source link

"JavaScript heap out of memory" running serve/build tasks in Angular app after upgrading to latest NX/Angular #22297

Closed danwellman closed 3 months ago

danwellman commented 5 months ago

Current Behavior

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 00007FF60B5F71AB node::SetCppgcReference+16075
 2: 00007FF60B56DCC6 DSA_meth_get_flags+79190
 3: 00007FF60B56FED5 DSA_meth_get_flags+87909
 4: 00007FF60BFDF061 v8::Isolate::ReportExternalAllocationLimitReached+65
 5: 00007FF60BFC87F8 v8::Function::Experimental_IsNopFunction+1336
 6: 00007FF60BE2A120 v8::Platform::SystemClockTimeMillis+659328
 7: 00007FF60BE271A8 v8::Platform::SystemClockTimeMillis+647176
 8: 00007FF60BE3C4BA v8::Platform::SystemClockTimeMillis+733978
 9: 00007FF60BE3CD37 v8::Platform::SystemClockTimeMillis+736151
10: 00007FF60BE4B62F v8::Platform::SystemClockTimeMillis+795791
11: 00007FF60BB0BBE5 v8::CodeEvent::GetFunctionName+116773
12: 00007FF5AC05AAFA

Expected Behavior

Build/serve to work

GitHub Repo

No response

Steps to Reproduce

  1. nx migrate@latest
  2. npm install
  3. npx nx migrate --run-migrations
  4. node --max_old_space_size=12000 ./node_modules/nx/bin/nx serve
  5. FATAL ERROR...

Steps 1-3 all completed successfully. Running unit tests works as expected

Nx Report

Node   : 20.11.1
OS     : win32-x64
npm    : 10.2.4

nx (global)        : 18.0.8
nx                 : 18.0.8
@nx/js             : 18.0.8
@nx/jest           : 18.0.8
@nx/linter         : 18.0.8
@nx/eslint         : 18.0.8
@nx/workspace      : 18.0.8
@nx/angular        : 18.0.8
@nx/cypress        : 18.0.8
@nx/devkit         : 18.0.8
@nx/eslint-plugin  : 18.0.8
@nrwl/tao          : 18.0.8
@nx/web            : 18.0.8
@nx/webpack        : 18.0.8
typescript         : 5.3.3
---------------------------------------
Community plugins:
@ngrx/component-store : 17.0.1
@ngrx/data            : 17.0.1
@ngrx/effects         : 17.0.1
@ngrx/entity          : 17.0.1
@ngrx/router-store    : 17.0.1
@ngrx/store           : 17.0.1
@ngrx/store-devtools  : 17.0.1
devextreme-angular    : 23.1.7

Failure Logs

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory ----- Native stack trace -----

1: 00007FF60B5F71AB node::SetCppgcReference+16075 2: 00007FF60B56DCC6 DSA_meth_get_flags+79190 3: 00007FF60B56FED5 DSA_meth_get_flags+87909 4: 00007FF60BFDF061 v8::Isolate::ReportExternalAllocationLimitReached+65 5: 00007FF60BFC87F8 v8::Function::Experimental_IsNopFunction+1336 6: 00007FF60BE2A120 v8::Platform::SystemClockTimeMillis+659328 7: 00007FF60BE271A8 v8::Platform::SystemClockTimeMillis+647176 8: 00007FF60BE3C4BA v8::Platform::SystemClockTimeMillis+733978 9: 00007FF60BE3CD37 v8::Platform::SystemClockTimeMillis+736151 10: 00007FF60BE4B62F v8::Platform::SystemClockTimeMillis+795791 11: 00007FF60BB0BBE5 v8::CodeEvent::GetFunctionName+116773 12: 00007FF5AC05AAFA

Package Manager Version

No response

Operating System

Additional Information

I am trying to upgrade NX/Angular from a working Angular 16/NX 16 app to latest Angular/NX (17/17)

Prior to the upgrade the serve/build commands worked as expected.

After upgrade, both serve/build fail with JS heap allocation error.

I've tried various Node versions. I've tried updating --max_old_space_size=12000 with various values ranging from 8000 to 32000 and I tried it without specifying the --max_old_space_size option at all.

This is in a huge production app, which I cannot share. Creating a minimal repo will not help as it will be miniscule compared to the actual app.

TomONeill commented 5 months ago

I don't have the problem of running out of memory, but there definitely seems to have been a huge decrease in performance. My laptop slows down a bunch as soon as I serve apps with NX (18.0.8).

By the way: Angular 17.2 is not supported yet by NX 18. It will add support starting 18.1. See: https://nx.dev/nx-api/angular/documents/angular-nx-version-matrix#nx-and-angular-version-compatibility-matrix

hschmidtchen commented 5 months ago

I believe v17.3.0 introduced an issue where the max_old_space_size is no longer propagated to the angular build process. Could this be the same issue?

Here is how I was able to reproduce it: https://github.com/nrwl/nx/issues/22221

danwellman commented 5 months ago

FYI, I tried updating to Nx 18.1.2/Angular 17.2 today - still the same issue

KylerJohnsonDev commented 5 months ago

I'm seeing the same issue after running the migrations to update to Nx 18.1.2 and Angular 17.2. I may have a work-around, though.

I manually changed only the Nx package version back to 17.2.8 (which was the latest version without this issue AFAIK) and now I can build/serve my apps. I left all other packages on the updated version. It's not ideal, but it seems to be working.

Arthur-Carbonari commented 2 months ago

This is still very much an issue.

nx serve slows down my computer absurdly when running.

Initial Run: The initial run is acceptable.

Subsequent Rebuilds: Each subsequent rebuild takes progressively more time and significantly slows down the computer. After approximately 10 rebuilds, the rebuild time exceeds 20 seconds. Beyond that point, the time quickly increases to over a minute.

System Performance: At around 20+ rebuilds the computer becomes literally unusable while the rebuild is running due to memory issues. Then at one point it just crashes with an "Javascript heap out of memory" error.

Environment:

Angular: 18 Nx: 19.1.0

This behavior makes it extremely challenging to maintain productivity. Even after taking the serve down and start a new one the issue still persist and seems to only go away after restarting the computer.

cdskill commented 2 months ago

Hey there I just ran the migration command and I'm facing the exact same error, the topics seems to be closed. Why ? Is it resolved ? nx: 19.1.1 angular: 18.0.1

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xc9e850 node::Abort() [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 2: 0xb720ff  [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 3: 0xec1a70 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 4: 0xec1d57 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/home/xxxx/.nvm/versions/node/v20.10.0/bin/node]
 5: 0x10d3dc5  [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 6: 0x10ebc48 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 7: 0x10c1d61 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 8: 0x10c2ef5 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
 9: 0x10a0466 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
10: 0x14fb386 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/xxx/.nvm/versions/node/v20.10.0/bin/node]
11: 0x7e6b27699ef6 
github-actions[bot] commented 1 month ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.