I'm attempting to build a Next.js project on CircleCI using an ARM-based machine (specifically, arm.xlarge) which has 32GB of RAM. However, it seems to very quickly exit with an error about lack of memory. I've tried to increase the memory of the Node process all the way up to that of the machine, but with no luck - I receive the same error.
What's particularly strange is that the GCs have a tiny amount of memory utilization (3.5MB), and that it exits in sub-second time!
This build does work, if I swap out the arm resource type for an x86_64 resource type, and build a Docker image for the x86_64 platform instead. Obviously this doesn't cover my needs, but verifies the build works.
What might cause this very strange behaviour? What else can I do to further debug this issue?
What I've tried
Changing the Node version, ranging from 14 to 18.8.0
Changing the machine resource size
Changing the options of Docker, including adding a --memory flag to the extra-build-args field of the build job
Removing the yarn.lock
Purging the Node cache
Deleting the node_modules folder
Relevant resources:
Here's the trace:
#16 [11/11] RUN NODE_OPTIONS="--max_old_space_size=8192" yarn build
#16 sha256:da0777711cb35943386ef4812f2df1ff4932fb5bee717be330a217104e5240c7
#16 0.178
#16 0.178 <--- Last few GCs --->
#16 0.178
#16 0.178 [1:0x570e320] 100 ms: Mark-sweep 1.2 (3.5) -> 1.2 (3.5) MB, 2.2 / 0.0 ms (average mu = 0.818, current mu = 0.007) allocation failure scavenge might not succeed
#16 0.178 [1:0x570e320] 102 ms: Mark-sweep (reduce) 1.2 (3.5) -> 1.2 (3.5) MB, 2.3 / 0.0 ms (average mu = 0.704, current mu = 0.006) last resort GC in old space requested
#16 0.178 [1:0x570e320] 104 ms: Mark-sweep (reduce) 1.2 (2.5) -> 1.1 (3.5) MB, 2.3 / 0.0 ms (average mu = 0.549, current mu = 0.010) last resort GC in old space requested
#16 0.178
#16 0.178
#16 0.178 <--- JS stacktrace --->
#16 0.178
#16 0.178 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
#16 ERROR: process "/bin/sh -c NODE_OPTIONS=\"--max_old_space_size=8192\" yarn build" did not complete successfully: exit code: 132
------
> [11/11] RUN NODE_OPTIONS="--max_old_space_size=8192" yarn build:
------
Dockerfile:32
--------------------
31 |
32 | >>> RUN NODE_OPTIONS="--max_old_space_size=8192" yarn build
34 |
--------------------
error: failed to solve: rpc error: code = Unknown desc = process "/bin/sh -c NODE_OPTIONS=\"--max_old_space_size=8192\" CI_BUILD=${CI_BUILD} DEPLOYMENT_VERSION=${DEPLOYMENT_VERSION} yarn build" did not complete successfully: exit code: 132
Here's the relevant parts of the Dockerfile:
FROM node:14.18.0-alpine
WORKDIR /app
RUN apk update
RUN apk add python3
RUN apk add git gnupg jq g++ make py3-pip
COPY package.json yarn.lock ./
RUN yarn
RUN yarn add pm2#5.2.0 --global
COPY . .
RUN NODE_OPTIONS="--max_old_space_size=8192" yarn build
EXPOSE 3001
CMD [ "npx", ... ]
and here's the job from CircleCI config.yml:
build_and_push_image:
machine:
image: ubuntu-2004:202101-01
resource_class: arm.xlarge
steps:
- checkout
- docker/pull:
images: 'node:16.14.2'
- aws-ecr/build-and-push-image:
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
aws-cli-version: latest
create-repo: true
skip-when-tags-exist: true
dockerfile: Dockerfile
extra-build-args: >
--build-arg GPG_ENCRYPT_PASSPHRASE
--build-arg BUILD_STAGE
--build-arg CI_BUILD=true
platform: linux/arm64/v7
push-image: true
registry-id: AWS_ACCOUNT_ID
region: $AWS_REGION
repo: $PROJECT_NAME
tag: $version_tag
After a good few hours of debugging with trial and error, I fixed with the following changes to config.yml:
build_and_push_image:
machine:
image: ubuntu-2004:202101-01
resource_class: arm.xlarge
steps:
- checkout
- docker/pull:
images: 'node:16.14.2'
- aws-ecr/build-and-push-image:
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
aws-cli-version: latest
create-repo: true
skip-when-tags-exist: true
dockerfile: Dockerfile
extra-build-args: >
--build-arg GPG_ENCRYPT_PASSPHRASE
--build-arg BUILD_STAGE
--build-arg CI_BUILD=true
- platform: linux/arm64/v7
+ platform: linux/arm64
push-image: true
registry-id: AWS_ACCOUNT_ID
region: $AWS_REGION
repo: $PROJECT_NAME
tag: $version_tag
I'm not sure why this works, but here's my best thoughts for others who are blocked by this in the future:
Some miconfiguration of the docker buildx command from the CircleCI orb. I'm also noticing that a lot of people are having problems with Docker image caching using the orb, and maybe there's some issue with the command itself (see https://github.com/CircleCI-Public/aws-ecr-orb/issues/202). It looks something like this:
docker context create builder
# This here is interesting - it is using qemu to emulate for builds
# See https://github.com/tonistiigi/binfmt
docker run --privileged --rm tonistiigi/binfmt --install all
docker --context builder buildx create --use
docker --context builder buildx build \
-f "${PARAM_PATH}"/"${PARAM_DOCKERFILE}" \
${docker_tag_args} \
--platform "${PARAM_PLATFORM}" \
--progress plain \
"$#" \
"${PARAM_PATH}"
https://github.com/docker/buildx/issues/1036 missing qemu dependencies
https://github.com/moby/buildkit/issues/1946#issuecomment-767374876 libseccomp blocking unknown (new) syscalls
Have you checked the versions of OS and Node? The Versions should match. (x64=x64)
Related
<--- Last few GCs --->
[972:000001913A837320] 40900 ms: Mark-sweep 2049.2 (2066.3) -> 2047.3 (2059.3) MB, 2062.9 / 0.1 ms (+ 179.6 ms in 113 steps since start of marking, biggest step 8.9 ms, walltime since start of marking 2512 ms) (average mu = 0.153, current mu = 0.107) [972:000001913A837320] 42835 ms: Mark-sweep 2048.8 (2059.3) -> 2047.7 (2057.8) MB, 1845.1 / 0.0
ms (+ 81.8 ms in 23 steps since start of marking, biggest step 9.0 ms, walltime since start of marking 1935 ms) (average mu = 0.084, current mu = 0.004) al
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 00007FF68A20B3BD]
Security context: 0x002c4c9808d1 <JSObject>
1: _append [000002A11D9F9439] [D:\ReactProjects\plotlytest\myplotlysite\node_modules\#babel\generator\lib\buffer.js:~99] [pc=0000014BCF9DB744](this=0x03160f6401b1 <Buffer map = 000000A495510339>,0x02ab7a1c78c9 <String[#1]: >,151182,27,0x02ab7a1c01b9 <null>,0x02ab7a1c04b1 <undefined>,0x02ab7a1c06e9 <false>)
2: append [000002A11D9F9391] [D:\ReactPro...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF6895F5EBF napi_wrap+114095
2: 00007FF6895A0B46 v8::base::CPU::has_sse+66998
3: 00007FF6895A1946 v8::base::CPU::has_sse+70582
4: 00007FF689DB6E4E v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF689D9EF21 v8::SharedArrayBuffer::Externalize+833
6: 00007FF689C6B18C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
7: 00007FF689C763C0 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
8: 00007FF689C72EE4 v8::internal::Heap::PageFlagsAreConsistent+3204
9: 00007FF689C686E3 v8::internal::Heap::CollectGarbage+1283
10: 00007FF689C66D54 v8::internal::Heap::AddRetainedMap+2452
11: 00007FF689C8809D v8::internal::Factory::NewFillerObject+61
12: 00007FF6899EE06F v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1295
13: 00007FF68A20B3BD v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 0000014BCF9DB744
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! myplotlysite#0.1.0 start: `react-scripts start`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the myplotlysite#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Above is the error I am recieving. I followed a pretty standard set-up, identical to the one listed on this site: https://github.com/plotly/react-plotly.js/blob/master/README.md
I created a react app. When I create a react app and "npm start" the local host it works perfectly fine. This error occurs when I do the next step:
"npm install react-plotly.js plotly.js" after I do this, the local host no longer works and I get this error.
How can I fix this?
By the way, I'm curious, why does this error still exist for so many years? Is plotly not well for react or something?
There are a couple issues reported regarding this exact problem on the repo issues tracking, like:
JavaScript heap out of memory error with the quickstart Plot example.
Javascript runs out of memory when making production build
In these issues, we clearly see this is a problem with NodeJS <= 10 memory allocation issue and there are several solutions to this:
Try to upgrade your NodeJS version to latest 12.x version
Node >= 12 increases the heap sizes automatically and it will work. I suggesst you install Node Version Manager (nvm) for Windows which will allow you quickly and easily install and switch through multiple node version.
Manually increase max_old_space_size to React scripts
Increase heap size using max_old_space_size by adding this option with a memory size into the package.json script:
"scripts": {
...
"start": "react-scripts --max_old_space_size=4096 start",
"build": "react-scripts --max_old_space_size=4096 build",
...
}
Use Partial bundles
Partial bundles
Starting in v1.15.0, plotly.js also ships with several partial bundles:
basic
cartesian
geo
...
Starting in v1.39.0, each plotly.js partial bundle has a corresponding npm package with no dependencies.
Starting in v1.50.0, the minified version of each partial bundle is also published to npm in a separate "dist min" package.
plotly.js basic
The basic partial bundle contains trace modules scatter, bar and pie.
You can load the library from plotly.js-basic-dist which it's compiled and will consume less memory when bundling:
import React from "react";
// import Plot from "react-plotly.js";
import Plotly from "plotly.js-basic-dist";
import createPlotlyComponent from "react-plotly.js/factory";
const Plot = createPlotlyComponent(Plotly);
I'm facing with this issue of "JavaScript heap out of memory" when I deploy or ru service with 'serverless offiline' command.
I'm using nestjs - a node framework - and building the project for node 10x.
On my terminal I got this below.
I found some fixes like
type " node --max-old-space-size=1024 index.js" on terminal
use this package https://www.npmjs.com/package/increase-memory-limit
append on script tag in package.json some like ""scripts": {
"webpacker": "node --max_old_space_size=4096"
not of theses works.
any clue?
PS D:\m1_workspace\dw-api> serverless offline
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
<--- Last few GCs --->
al[21864:000001EF81231660] 20688 ms: Mark-sweep 1394.2 (1429.4) -> 1392.3 (1429.9) MB, 977.1 / 0.0 ms (+ 0.0 ms in 62 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 987 ms) (average mu = 0.074, current mu = 0.010) all[21864:000001EF81231660] 21557 ms: Mark-sweep 1392.3 (1429.9) -> 1392.2 (1427.9) MB, 868.1 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 868 ms) (average mu = 0.037, current mu = 0.001) allo
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x002e2c61e6e9 <JSObject>
0: builtin exit frame: splice(this=0x03a8c4a97e89 <JSArray[8]>,0x0237e40868f9 <TypeObject map = 000001453BA516C9>,0,8,0x03a8c4a97e89 <JSArray[8]>)
1: getUnionType(aka getUnionType) [00000057B5C33821] [D:\m1_workspace\dw-api\node_modules\#hewmen\serverless-plugin-typescript\node_modules\typescript\lib\typescript.js:~34245] [pc=000003F28C0363E9](this=0x007f886026f1 <undefined>,types=0x010...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
A quick workaround is to try to run below command first:
export NODE_OPTIONS=--max_old_space_size=8192
I have a large serverless project which ran into similar issue when I tried to deploy with "sls deply". And this workaround works for me.
Hope it can help.
This was happening to me too -
I realized I had defined my serverless configuration to package each lambda individually.
Which looks like this:
package:
individually: true
Changing that to:
package:
individually: false
worked for me.
(Of course if packaging your lambda functions individually is crucial for you, then you'll lose that, but for me it wasn't).
I am trying to build Mattermost on an armv7a host, but Node is running out of memory during the webpack build. The solution for this seems to be supposed to set max_old_space_size in NODE_OPTIONS, but counterintuitively doing this seems to cause the build to fail immediately the first time node is run.
The host has 2G of RAM, but I have added 12G of swap to no effect.
CPU: Marvell Armada 370/XP (Device Tree) (4) # 1.333GHz
Node: v13.13.0
Crash when building normally, this occurs after about 30 minutes:
Building mattermost Webapp
rm -rf dist
npm run build
> mattermost-webapp#0.0.1 build /var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client
> cross-env NODE_ENV=production webpack --display-error-details --verbose
<--- Last few GCs --->
[17346:0x1e80ee8] 2121678 ms: Mark-sweep 501.2 (506.3) -> 500.7 (506.3) MB, 1640.3 / 0.0 ms (average mu = 0.108, current mu = 0.029) allocation failure scavenge might not succeed
[17346:0x1e80ee8] 2123903 ms: Mark-sweep 501.2 (506.3) -> 500.8 (506.3) MB, 2178.0 / 0.0 ms (average mu = 0.064, current mu = 0.021) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1468e00]
1: StubFrame [pc: 0x14098a4]
Security context: 0x31940491 <JSObject>
2: /* anonymous */(aka /* anonymous */) [0x9e4bbf89] [/var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client/node_modules/webpack-sources/l
ib/applySourceMap.js:~58] [pc=0x9c9a9b44](this=0x40f0027d <undefined>,0x4c40d721 <String[2]: e}>,0xa5f1ebcd <Object ...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mattermost-webapp#0.0.1 build: `cross-env NODE_ENV=production webpack --display-error-details --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mattermost-webapp#0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Crash when adding NODE_OPTIONS=max_old_space_size=4196 (occurs immediately):
make -j4 build
Getting dependencies using npm
npm install
<--- Last few GCs --->
[35:0x1ea1e00] 394 ms: Mark-sweep 1.0 (2.5) -> 0.9 (3.5) MB, 10.7 / 0.0 ms (average mu = 0.724, current mu = 0.096) allocation failure GC in old space requested
[35:0x1ea1e00] 401 ms: Mark-sweep 0.9 (3.5) -> 0.9 (2.0) MB, 6.6 / 0.0 ms (average mu = 0.627, current mu = 0.063) last resort GC in old space requested
[35:0x1ea1e00] 409 ms: Mark-sweep 0.9 (2.0) -> 0.9 (2.0) MB, 8.6 / 0.0 ms (average mu = 0.463, current mu = 0.005) last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1489e00]
Security context: 0x375c0491 <JSObject>
1: test [0x375c4d6d](this=0x5cfb2121 <JSRegExp <String[#14]: (?:^|\/)\.?\.$>>,0x33167c71 <String[#27]: ../lib/utils/unsupported.js>)
2: /* anonymous */(aka /* anonymous */) [0x375ca1a5] [internal/per_context/primordials.js:23] [bytecode=0x375f6695 offset=28](this=0x4938027d <undefined>,0x5cfb2121 <JSRegExp <String[#14]: (?:^|\/)\.?\.$>>)
3: arguments adap...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
make: *** [Makefile:36: node_modules] Aborted
Why does changing max_old_space_size cause Node to run out of memory immediately?
Edit: some more information to add...I have been using https://github.com/Data-Wrangling-with-JavaScript/nodejs-memory-test as a minimal test case to demonstrate. It would seem that Node is refusing to consider swap space as usable memory. For example, if I run:
$ node nodejs-memory-test/index.js
It allocates up to the last line:
Allocated since start 0.49 GB
before crashing. If I run:
$ NODE_OPTIONS="--max-old-space-size=1024" node nodejs-memory-test/index.js
it successfully runs up to
Allocated since start 0.98 GB
before crashing.
However, if I run:
NODE_OPTIONS="--max-old-space-size=8196" node nodejs-memory-test/index.js
it only gets through a handful of lines before dying on
Allocated since start 0.01 GB
Can somebody help me understand what is going on?
I have started to experience node crashes during ng build --prod, due to increasing memory requirements of my angular-cli app. I have seen solutions like this:
Stackoverflow question
However, I am unsure how to configure this change in docker.
Dockerfile
FROM node:11.6.0-alpine AS builder
COPY . ./visualizationadmin-ng
WORKDIR /visualizationadmin-ng
RUN npm i
RUN $(npm bin)/ng build --aot --prod
FROM nginx:1.15.8-alpine
RUN chmod g+rwx /var/cache/nginx /var/run /var/log/nginx
COPY --from=builder /visualizationadmin-ng/dist/visualizationadmin-ng/ /usr/share/nginx/html
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
# OpenShift port
EXPOSE 8080
Docker-compose
version: '2.3'
services:
angular:
hostname: localhost
container_name: visualizationadmin-ng
build: .
ports:
- 8080:80
environment:
NODE_OPTIONS: ${NODE_OPTIONS}
.env file
NODE_OPTIONS=--max-old-space-size=4096 ng bundle
When I run docker-compose I get the following error log
<--- Last few GCs --->
[1:0x563fd8b258c0] 259664 ms: Mark-sweep 1174.6 (1443.6) -> 1162.0 (1447.6) MB, 1332.2 / 0.0 ms (average mu = 0.206, current mu = 0.112) allocation failure scavenge might not succeed
[1:0x563fd8b258c0] 260886 ms: Mark-sweep 1177.1 (1447.6) -> 1161.6 (1448.1) MB, 1170.0 / 0.0 ms (average mu = 0.133, current mu = 0.042) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x16812784fb5d]
Security context: 0x2ae71059d921 <JSObject>
1: yn(aka yn) [0x7a102207399] [/visualizationadmin-ng/node_modules/terser/dist/bundle.min.js:~1] [pc=0x16812b2f9406](this=0x29a3dc8025b1 <undefined>,0x29a3dc8025b1 <undefined>)
2: /* anonymous */ [0x7a102203919] [/visualizationadmin-ng/node_modules/terser/dist/bundle.min.js:~1] [pc=0x16812b1b0471](this=0x128f61ced9d9 <AST_SymbolRef map = 0x3eb1d6dae2...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
ERROR: Service 'angular' failed to build: The command '/bin/sh -c $(npm bin)/ng build --aot --prod' returned a non-zero code: 139
The docker fails both locally and in gitlab ci/cd. My local docker configuration settings are attached.
When trying to build an Angular project on a Linux server with -aot flag, I get an error. I tried upgrading my instance to a higher CPU core, more RAM and turn on a SWAP partition but still the error just occur faster.
Here's while trying to build from terminal along with the command with the flags I use.
ng build --target=production --environment=prod --aot
Your global Angular CLI version (1.7.2) is greater than your local
version (1.4.7). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
10% building modules 5/5 modules 0 activeTemplate parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("
[WARNING ->]<template [ngIf]="!isClosed">
<div [class]="'alert alert-' + type" role="alert" [ngClass]="classes""): ng:///****************node_modules/ngx-bootstrap/alert/alert.component.d.ts.AlertComponent.html#1:0
92% chunk asset optimization
<--- Last few GCs --->
133611 ms: Mark-sweep 1302.6 (1435.2) -> 1297.8 (1435.2) MB, 1112.6 / 0.0 ms [allocation failure] [GC in old space requested].
134724 ms: Mark-sweep 1297.8 (1435.2) -> 1297.7 (1435.2) MB, 1112.7 / 0.0 ms [allocation failure] [GC in old space requested].
135854 ms: Mark-sweep 1297.7 (1435.2) -> 1302.7 (1406.2) MB, 1129.8 / 0.0 ms [last resort gc].
136983 ms: Mark-sweep 1302.7 (1406.2) -> 1307.9 (1406.2) MB, 1128.8 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0xb8bacacfb39 <JS Object>
1: find_variable [0xb8baca04381 <undefined>:~3539] [pc=0xbdb4151ee32] (this=0xa9144042161 <an AST_Function with map 0xd6ccb950f99>,name=0x1f852792bb29 <String[12]: DOMException>)
2: visit [0xb8baca04381 <undefined>:3449] [pc=0xbdb4151d969] (this=0x3da6d780b621 <a TreeWalker with map 0xd6ccb9394c9>,node=0x2f9919fb8e91 <an AST_SymbolRef with map 0xd6ccb9628c9>,descend=0x2e68ca83edd1 <JS Fu...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [ng]
2: 0x109bf8c [ng]
3: v8::Utils::ReportApiFailure(char const*, char const*) [ng]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [ng]
5: v8::internal::Factory::NewInternalizedStringImpl(v8::internal::Handle<v8::internal::String>, int, unsigned int) [ng]
6: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [ng]
7: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [ng]
8: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [ng]
9: 0xed3501 [ng]
10: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [ng]
11: 0xbdb262092a7
Aborted (core dumped)
I tried the solution mentioned here, https://www.npmjs.com/package/increase-memory-limit
But still with no luck
For prod build, run following command:
node --max_old_space_size=4096 node_modules/#angular/cli/bin/ng build
--target production
For more optimization flags, below command:
It has inbuilt cache busting and other goodies:
node --max_old_space_size=4096 node_modules/#angular/cli/bin/ng build
--target production --build-optimizer --vendor-chunk
try running
node --max-old-space-size=8192
where 8192 is size in MB
As Filipe Silva recommends in the angular-cli repository, add a new entry in the scripts section of your package.json file:
"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/#angular/cli/bin/ng",
and use it this way:
npm run ng-high-memory --
You have to remember to use the double dash before the arguments, otherwise they might not be parsed correctly:
npm run ng-high-memory -- serve
This does not look like a hardware limitation problem as such which can be resolved by upgrading the memory or processor.
I once had a build running out of memory, but it turned out that there was a circular reference where a source file A required a source file B and then B also required A. It was a code design issue, of course.
I would suggest you to try a simple build first and check to see if it goes well.
ng build
Also, the Angular doc mentions that when using ng build --prod, (not --target=production), it performs an AOT compilation, among other things:
https://angular.io/guide/deployment
The --prod meta-flag engages the following optimization features.
Ahead-of-Time (AOT) Compilation: pre-compiles Angular component templates.
Production mode: deploys the production environment which enables production mode.
You might want to install the latest version of the Angular CLI and see if that helps.
I faced same issue on Angular 4 project. The problem is my Node Js version is not compatible Angular 4, I installed Node Js v6.17.1 and problem resolved for me.
For more details Angular and Node Js compatibility you can visit this link : Is there a compatibility list for Angular / Angular-CLI and Node.js?
I faced with the same problem. as a solution adding Swap file worked for me.