1
votes

I've been working on my Angular 8 Universal project for a month. Everything was OK with making SSR builds but a couple of days ago I got stuck with this strange behavior of Webpack or Angular framework, I don't know.

I get the error :

65% building 464/465 modules 1 active p:\web\nodejs projects\ng-express\dist\server.js


FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

and I noticed that the dist/server.js file is larger than...50MB! It's a bit strange.

enter image description here

I tried to find any solutions but all of them concern making just a build but not SSR build:

node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --aot

I need to execute: "npm run build:ssr" command and it's impossible to add "node --max_old_space_size=4096" command before my one.

To be honest, why I receive this error at all? How to sort it out?

Any help would be highly appreciated!

1

1 Answers

1
votes

This issue has been resolved, at least for me, with the latest LTS node version. You can try to update to Node.js v12.13.

If you do not want that, then you should know that webpack + angular + node is known for causing this issue. You can however look at your package.json

"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"build:client-and-server-bundles": "ng build --prod && ng run angular.io-example:server",
"webpack:server": "webpack --config webpack.server.config.js --progress --colors"

if this is in your package.json, you should add extra entries:

"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
"build:ssr:high-mem": "npm run ng-high-memory -- build --prod && npm run ng-high-memory -- run angular.io-example:server && npm run webpack:server"

You can then run the build:

npm run build:ssr:high-mem

This is a bit untested though, so I do advise you to just update your Node version to resolve it