bjwhip
bjwhip

Reputation: 467

Nrwl NX JavaScript heap out of memory on lint

I am working within an Nx monorepo with many Angular 15 applications, and some shared libraries. I generated a new Angular application using the nx cli, which worked great. I can serve and build the application without issue.

The issue comes when I add the tsconfig files for the new application to my eslintrc.json file

"overrides": [
  "parserOptions": {
    "project": [
      "apps/new-app/tsconfig.*?.json"
      "libs/shared/tsconfig.*?.json"
      */ -----
        15 others
      -----/*
    ]
  }
]

If I add my new application to the parserOptions, then run

nx affected --target=lint

I get this error for the shared library which has not been touched

<--- Last few GCs --->

[18664:0000015D230EE780]    71334 ms: Scavenge 4044.3 (4127.2) -> 4039.4 (4128.5) MB, 12.6 / 0.0 ms  (average mu = 0.835, current mu = 0.632) allocation failure 
[18664:0000015D230EE780]    71386 ms: Scavenge 4047.0 (4130.1) -> 4043.9 (4131.8) MB, 14.5 / 0.1 ms  (average mu = 0.835, current mu = 0.632) allocation failure 
[18664:0000015D230EE780]    72392 ms: Scavenge 4048.8 (4131.8) -> 4045.8 (4150.1) MB, 989.7 / 0.0 ms  (average mu = 0.835, current mu = 0.632) allocation failure 


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF7DB8A0B5F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+124015
 2: 00007FF7DB82C916 v8::internal::wasm::WasmCode::safepoint_table_offset+64182
 3: 00007FF7DB82D992 v8::internal::wasm::WasmCode::safepoint_table_offset+68402
 4: 00007FF7DC161D94 v8::Isolate::ReportExternalAllocationLimitReached+116
 5: 00007FF7DC14C35D v8::SharedArrayBuffer::Externalize+781
 6: 00007FF7DBFEF93C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
 7: 00007FF7DBFECA54 v8::internal::Heap::CollectGarbage+4244
 8: 00007FF7DBFEA3D0 v8::internal::Heap::AllocateExternalBackingStore+2000
 9: 00007FF7DC00EF56 v8::internal::Factory::NewFillerObject+214
10: 00007FF7DBD416F5 v8::internal::DateCache::Weekday+1797
11: 00007FF7DC1EFA71 v8::internal::SetupIsolateDelegate::SetupHeap+494417
12: 0000015D254F5AEA 

If I remove the new app from the parserOptions and run lint, everything the linter succeeds everywhere except the new application, for which the error tells me to add the tsconfig to the parserOptions

I am running on windows using node version v16.18.1 and I have tried increasing the memory available using --max-old-space-size=6144/--max_old_space_size=6144 in several ways.

Does anyone know what is causing this issue, or how to fix it? While everything works except the nx lint, my company uses nx built in lint command to verify code before it can be pushed or merged

Upvotes: 10

Views: 5480

Answers (1)

Tyler Hendrickson
Tyler Hendrickson

Reputation: 21

For me, the fix was to change how I was specifying the tsconfig.json in each of my apps. Originally, I had

"project": ["tsconfig.base.json"]

Changing this to

"project": ["apps/{{app-name}}/tsconfig.*?.json"]

seemed to fix the issue with all of the correct files included and no memory issues.

Pretty weird issue, I'd be interested to hear an explanation. For me, it popped up randomly when I migrated to Nx 16 and Angular 16—even after running the migrations. Not sure if yours was a different scenario. Interestingly enough, there were no issues linting on a CI machine (Ubuntu 22.04.2, x64), but both my dev machine and another machine (both macOS 13.4, arm64) had the problem.

Upvotes: 2

Related Questions