2

I have an Angular application that has recently been converted to Angular Universal. The application is based on Angular 15 and is running inside a Docker container. The command used to initiate the server is "npm serve:ssr". The application runs fine for a day or two, but after that, it throws the error "ineffective mark-compacts near heap limit allocation failed - javascript heap out of memory".

To address this issue, I tried increasing the memory by adding the flag "max-old-space-size" to 3072. I modified the "serve:ssr" script in the package.json file to "node --max-old-space-size=3072 {project-name}/server/main.js". However, the problem still persists, causing my server to go down.

Here's the code snippet for the modified "serve:ssr" script in the package.json file

"scripts": {
  "serve:ssr": "node --max-old-space-size=3072 {project-name}/server/main.js"
},

Could you please help me understand why I'm still encountering this "out of memory" error despite increasing the memory allocation? Are there any additional steps or configurations I should consider to prevent this issue from occurring? Thank you in advance for your assistance.

Pawanpreet Singh
  • 229
  • 5
  • 12
  • My hosting provider told me about this. Have you considered using .NET to host your angular app? Or is that not an option? – Pieterjan May 20 '23 at 07:09
  • Thank you for your suggestion. I wasn't aware that hosting an Angular app with .NET was an option. Could you please provide more information on how Angular SSR can be hosted with .NET? I would like to understand if this approach can help resolve the "javascript heap out of memory" error in my Docker container. Any insights or references you can provide would be greatly appreciated. Thank you! – Pawanpreet Singh May 21 '23 at 17:22
  • [Here's a guide](https://medium.com/@pieterjandeclippel/server-side-rendering-in-asp-net-core-angular-2022-version-7aaed8157976). Microsoft doesn't support server side rendering anymore, so the `UseSpaPrerendering` middleware is no longer available in .NET 5, 6 and 7. But I migrated the code [here](https://github.com/MintPlayer/MintPlayer.AspNetCore.SpaServices.Routing) and already made several optimizations – Pieterjan May 21 '23 at 17:31

1 Answers1

0

This seems to be an issue with our code, I have fixed it by avoiding the memory leaks, by using strategies described in this link. https://stackoverflow.com/a/70527954/3493655

Pawanpreet Singh
  • 229
  • 5
  • 12