Trouble with 'build-dev' during development setup

Dear @community,

I followed the guidelines in CHT Core dev environment setup.

I got the following issue while running npm run build-dev

> @medic/cht-datasource@1.0.0 build
> tsc -p tsconfig.build.json


> medic@4.18.0 build-webapp-dev
> cd webapp && npm run build -- --configuration=development && npm run compile


> medic-webapp@0.1.0 build
> ng build --configuration=development

⠋ Generating browser application bundles (phase: setup)...    TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and "false" respectively by the Angular CLI. To control ECMA version and features use the Browserslist configuration. For more information, see https://angular.dev/tools/cli/build#configuring-browser-compatibility
    NOTE: You can set the "target" to "ES2022" in the project's tsconfig to remove this warning.
⠹ Generating browser application bundles (phase: sealing)...
<--- Last few GCs --->

[1712:0x27ff0000]    85344 ms: Mark-Compact 948.7 (979.8) -> 942.5 (981.3) MB, pooled: 0 MB, 711.76 / 0.00 ms  (average mu = 0.333, current mu = 0.038) allocation failure; scavenge might not succeed
[1712:0x27ff0000]    86303 ms: Mark-Compact 950.4 (981.3) -> 944.9 (983.6) MB, pooled: 0 MB, 938.91 / 0.00 ms  (average mu = 0.184, current mu = 0.020) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

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

 1: 0xe36196 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [ng build --configuration=development]
 2: 0x123f4a0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [ng build --configuration=development]
 3: 0x123f777 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [ng build --configuration=development]
 4: 0x146d1a5  [ng build --configuration=development]
 5: 0x1486a19 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --configuration=development]
 6: 0x145b0e8 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build --configuration=development]
 7: 0x145c015 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build --configuration=development]
 8: 0x1434cee v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build --configuration=development]
 9: 0x18962ec v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build --configuration=development]
10: 0x1df2476  [ng build --configuration=development]
Aborted (core dumped)

Seems like memory problem. How do I increase my memory limit?

Hi @Ubayed_Bin_Sufian

Node running out of memory when building the app is not something that we would expect.
Can you please share more details about your system, like: your OS version, Node version, available RAM and CPU, the branch that you are trying to build and whether you have made any changes.

Thanks!

Hi @diana,

Thank you for your response!

Here are the details you requested:

  • OS version: [Ubuntu 24.04.2 LTS / Windows 10 Pro]
  • Node version: [v22.14.0]
  • Available RAM: [~500 MB]
  • CPU: [Intel(R) Core™ i5-7200U CPU @ 2.50GHz 2.71 GHz]
  • Branch: [Master]
  • Changes made: [None, I am just trying to run the webapp locally.]

Hi @Ubayed_Bin_Sufian

500MB ram is really low. Are you running Linux in a VM? Can you please increase the available RAM?

Hi @diana,

(I am a newbie in using Linux.)
I am using WSL 2. I think, yes. I am running Linux in a VM.

After researching a bit, i placed .wslconfig file in C:\Users\<YourUsername>\.wslconfig, with the following text

[wsl2]
memory=1536MB
processors=2
swap=512MB
localhostForwarding=true

I even tried the guideline in the link: Redirecting.

Both of the above steps didn’t help.

Could you please let me know if there is any other alternative?

Also, I found out about this part of the error too,

ubayed@DESKTOP-D2J0Q2L:~$ cd ~/cht-core && npm run build-dev-watch

> medic@4.18.0 build-dev-watch
> npm run build-dev && (npm run --prefix shared-libs/cht-datasource build-watch & npm run --prefix webapp build-watch & node ./scripts/build/watch.js)


> medic@4.18.0 build-dev
> npm run clean && ./scripts/build/build-prepare.sh && npm run --prefix shared-libs/cht-datasource build && npm run build-webapp-dev && ./scripts/build/copy-static-files.sh


> medic@4.18.0 clean
> rm -rf build api/build



Running "npm ci" on webapp


npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE   package: 'enketo-core@7.2.5',
npm warn EBADENGINE   required: { node: '>=14 <17', npm: '>=6 <7' },
npm warn EBADENGINE   current: { node: 'v22.14.0', npm: '10.9.2' }
npm warn EBADENGINE }
npm warn deprecated formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau

Hi @Ubayed_Bin_Sufian

I’m a newbie using WSL, but I think that you should change this config and grant it more resources:

[wsl2]
memory=8GB
processors=10
swap=512MB
localhostForwarding=true

and then apparently you need to restart WSL. I believe you can find a rich abundance of learning resources about WSL online.
I believe you would need at least 8GB of memory to run the CHT, and that would be a very bare minimum for development, though I’m afraid more is required for having a smooth experience.

Hi @diana,

Thanks a lot for your response.

I got this article which actually solved the issue. This particular code helped the web app to compile.

export NODE_OPTIONS=--max-old-space-size=1540

But a new problem arose.

I used 4 terminals of Ubuntu 24.04 to run the webapp.
One for docker, one for web app compile, one for dev api and one for sentinel api. I could not use the fourth one, due to shortage of RAM.

This aligns with your answer, I need at least 8 GB of RAM.

Thanks again for your prompt response. For time being, its a challenge for me to afford a new workstation. I will try to contribute to sectors which requires less compute power such as documentation.

2 Likes

Hi all!

Great to see folks troubleshooting this. I do want to call out what the Microsoft defaults are for these values:

  • memory - 50% of windows host
  • processors - same as windows host
  • swap - 25% of windows host
  • localhostForwarding - true

So if folks are having issues running the CHT because their WSL2 doesn’t have enough memory, this means their Windows machine has 8GB or less of RAM. While you can tell WSL2 to use up the same amount of RAM physically in your machine, I’m not sure if this is a good idea.

I think a better approach here instead of requesting folks update their config is to instead update our app dev hosting requirements to be “8 GB RAM or more” instead of “4 GB RAM”.

Maybe before we make any changes, @Ubayed_Bin_Sufian - can you confirm how much RAM you physical windows machine has? How much is WSL taking up right now?

1 Like