0
votes

I am working on an angular 8 project and trying to build it for production but every time I run the build command, it shows

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

I am unable to figure out the error as the application is working fine on development mode.

npm log file:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli   '/usr/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build:client-and-server-bundles' ]
2 info using npm@6.13.4
3 info using node@v10.19.0
4 verbose run-script [ 'prebuild:client-and-server-bundles',
4 verbose run-script   'build:client-and-server-bundles',
4 verbose run-script   'postbuild:client-and-server-bundles' ]
5 info lifecycle angularproject@1.0.0~prebuild:client-and-server-bundles: angularproject@1.0.0
6 info lifecycle angularproject@1.0.0~build:client-and-server-bundles: angularproject@1.0.0
7 verbose lifecycle angularproject@1.0.0~build:client-and-server-bundles: unsafe-perm in lifecycle true
8 verbose lifecycle angularproject@1.0.0~build:client-and-server-bundles: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ekodev/angular_b2b/node_modules/.bin:/usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ekodev/angular_b2b/node_modules/.bin:/home/ekodev/bin:/home/ekodev/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle angularproject@1.0.0~build:client-and-server-bundles: CWD: /home/ekodev/angular_b2b
10 silly lifecycle angularproject@1.0.0~build:client-and-server-bundles: Args: [ '-c',
10 silly lifecycle   'node --max_old_space_size=32276 node_modules/@angular/cli/bin/ng build --prod --aot --output-hashing=all && ng run angularproject:server:production' ]
11 silly lifecycle angularproject@1.0.0~build:client-and-server-bundles: Returned: code: 134  signal: null
12 info lifecycle angularproject@1.0.0~build:client-and-server-bundles: Failed to exec build:client-and-server-bundles script
13 verbose stack Error: angularproject@1.0.0 build:client-and-server-bundles: `node --max_old_space_size=32276 node_modules/@angular/cli/bin/ng build --prod --aot --output-hashing=all && ng run angularproject:server:production`
13 verbose stack Exit status 134
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid angularproject@1.0.0
15 verbose cwd /home/ekodev/angular_b2b
16 verbose Linux 4.4.0-169-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build:client-and-server-bundles"
18 verbose node v10.19.0
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 134
22 error angularproject@1.0.0 build:client-and-server-bundles: `node --max_old_space_size=32276 node_modules/@angular/cli/bin/ng build --prod --aot --output-hashing=all && ng run angularproject:server:production`
22 error Exit status 134
23 error Failed at the angularproject@1.0.0 build:client-and-server-bundles script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]

I tried searching for the issue but unable to find anything.

2

2 Answers

0
votes

Fixed the issue by updating the node version to v12.16.1. Not sure if this is the right way but at least it fixed my issue for now.

-1
votes

try to fire this command on your production server to create build first time

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod