Reputation: 5022
Node version is v0.11.13
Memory usage during crash according to sudo top
not raises over 3%
Code that reproduces this error:
var request = require('request')
var nodedump = require('nodedump')
request.get("http://pubapi.cryptsy.com/api.php?method=marketdatav2",function(err,res)
{
var data
console.log( "Data received." );
data = JSON.parse(res.body)
console.log( "Data parsed." );
data = nodedump.dump(data)
console.log( "Data dumped." );
console.log( data )
})
To check if that a recursion stack size problem I have ran next code with --stack-size=60000 parameter
var depth = 0;
(function recurse() {
// log at every 500 calls
(++depth % 500) || console.log(depth);
recurse();
})();
and have got
264500
Segmentation fault
Then I ran code which gives me FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory with the same --stack-size=60000 parameter and haven't got Segmentation fault
.
So I conclude CALL_AND_RETRY_LAST
has nothing common with the recursion stack size.
How could I solve this problem? I believe there is enough free memory on my computer to finish this task successfully.
There are similar questions on stackoverflow but none of this questions are about CALL_AND_RETRY_LAST
that's why I created separate question.
Upvotes: 211
Views: 249597
Reputation: 1131
You should also check if you accidentally installed the x86 version of node instead of x64. Happened to me, because nodejs.org preselected x86 on my x64 machine...
Upvotes: 11
Reputation: 17482
I replaced
ng build --prod
with
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
So instead of using ng build --prod
just use above command starts with node..
. To generate production build there is not need to use ng server --prod
.
If you don't want to use --prod
, just remove it.
So these are the commands to use in vs code terminal
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve
Upvotes: 2
Reputation: 325
#!/usr/bin/env node --max-old-space-size=4096 in the ionic-app-scripts.js dint work
But after Modifying: the following file it worked
node_modules/.bin/ionic-app-scripts.cmd
By adding:
@IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0..@ionic\app-scripts\bin\ionic-app-scripts.js" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node --max_old_space_size=4096 "%~dp0..@ionic\app-scripts\bin\ionic-app-scripts.js" %* )
Upvotes: 2
Reputation: 1013
In a Windows Machine run below command
set NODE_OPTIONS=--max_old_space_size=4096
Upvotes: 7
Reputation: 712
Anyone getting this error with Azure build pipelines, try the below step to change environment variable of build agent
Add an Azure build pipeline task
-> Azure powershell script:Inlinescript
before Compile with below settings
- task: AzurePowerShell@3
displayName: 'Azure PowerShell script: InlineScript'
inputs:
azureSubscription: 'NYCSCA Azure Dev/Test (ea91a274-55c6-461c-a11d-758ef02c2698)'
ScriptType: InlineScript
Inline: '[Environment]::SetEnvironmentVariable("NODE_OPTIONS", "--max_old_space_size=16384", "Machine")'
FailOnStandardError: true
azurePowerShellVersion: LatestVersion
Upvotes: 3
Reputation: 1743
$ sudo npm i -g increase-memory-limit
Run from the root location of your project:
$ increase-memory-limit
This tool will append --max-old-space-size=4096 in all node calls inside your node_modules/.bin/* files.
Node.js version >= 8 - DEPRECATION NOTICE
Since NodeJs V8.0.0, it is possible to use the option --max-old-space-size
. NODE_OPTIONS=options...
$ export NODE_OPTIONS=--max_old_space_size=4096
Upvotes: 61
Reputation: 3627
If you have a look at the source: github/v8, it seems that you try to reserve a very big object.According to my experience it happens if you try to parse a huge JSON object, but when I try to parse your output with JSON and node0.11.13, it just works fine.
You don't need more --stack-size
, you need more memory: --max_new_space_size
and/or --max_old_space_size
.
The only hint I can give you beside that is trying another JSON-parser and/or try to change the input format to JSON line instead of JSON only.
Upvotes: 128
Reputation: 2895
The increase-memory-limit
module has been deprecated now.
As of Node.js v8.0 shipped August 2017, we can now use the NODE_OPTIONS
env variable to set the max_old_space_size
globally.
export NODE_OPTIONS=--max_old_space_size=4096
Ref URL: https://github.com/endel/increase-memory-limit
Upvotes: 23
Reputation: 21
npm install -g increase-memory-limit
increase-memory-limit
OR
C:\Users\{user_name}\AppData\Roaming\npm
--max_old_space_size=8192
to the IF
and ELSE
blocknow ng.cmd file looks like this after the change:
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "--max_old_space_size=8192" "%~dp0\node_modules\@angular\cli\bin\ng" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "--max_old_space_size=8192" "%~dp0\node_modules\@angular\cli\bin\ng" %*
)
Upvotes: 2
Reputation: 185
I was facing this issue in ionic and tried many solutions but solved this by running this.
For MAC: node --max-old-space-size=4096 /usr/local/bin/ionic cordova build android --prod
For Windows: node --max-old-space-size=4096 /Users/{your user}/AppData/Roaming/npm/node_modules/ionic/bin/ionic cordova build windows --prod
Upvotes: 2
Reputation: 373
this error occurs when required memory allocated for execution is less than memory required for running process. By default, Node memory size is 512 mb to increase this you need to type the following command :
node --max-old-space-size= <NewSize> <fileName>
Upvotes: 1
Reputation: 8152
I found that max_new_space_size
is not an option in node 4.1.1 and max_old_space_size
alone did not solve my problem. I am adding the following to my shebang and the combination of these seems to work:
#!/usr/bin/env node --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096
[EDIT]: 4096 === 4GB of memory, if your device is low on memory you may want to choose a smaller amount.
[UPDATE]: Also discovered this error while running grunt which previously was run like so:
./node_modules/.bin/grunt
After updating the command to the following it stopped having memory errors:
node --max_old_space_size=2048 ./node_modules/.bin/grunt
Upvotes: 31
Reputation: 293
My working solution is:
npm install --save-dev cross-env
or npm install -g cross-env
.package.json
add new build script...
"build:prod:ios": "cross-env NODE_OPTIONS='--max-old-space-size=8192' ionic cordova build ios --prod --release"
...
Use that command to build next time.
npm run build:prod:ios
Problem solved.
Upvotes: 10
Reputation: 4156
Note: see the warning in the comments about how this can affect Electron applications.
As of v8.0 shipped August 2017, the NODE_OPTIONS environment variable exposes this configuration (see NODE_OPTIONS has landed in 8.x!). Per the article, only options whitelisted in the source (note: not an up-to-date-link!) are permitted, which includes "--max_old_space_size"
. Note that this article's title seems a bit misleading - it seems NODE_OPTIONS had already existed, but I'm not sure it exposed this option.
So I put in my .bashrc
:
export NODE_OPTIONS=--max_old_space_size=4096
Upvotes: 33
Reputation: 662
I was seeing this issue when I was creating a bundle to react-native. Things I tried and didn't work:
node --max_old_space_size
, intrestingly this worked locally for me but failed on jenkins and I'm still not sure what goes wrong with jenkinsThing that did work for me:
I was importing a really big file in the code. The way I resolved it was by including it in the ignore
list in .babelrc
something like this:
{
"presets": ["react-native"],
"plugins": ["transform-inline-environment-variables"],
"ignore": ["*.json","filepathToIgnore.ext"]
}
It was a .js
file which did not really needed transpiling and adding it to the ignore list did help.
Upvotes: 2
Reputation: 6527
An alternative solution is to disable the AOT compiler:
ng build --prod --aot false
Upvotes: 0
Reputation: 828
Just a variation on the answers above.
I tried the straight up node command above without success, but the suggestion from this Angular CLI issue worked for me - you create a Node script in your package.json
file to increase the memory available to Node when you run your production build.
So if you want to increase the memory available to Node to 4gb (max-old-space-size=4096
), your Node command would be node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --prod
. (increase or decrease the amount of memory depending on your needs as well - 4gb worked for me, but you may need more or less). You would then add it to your package.json 'scripts' section like this:
"prod": "node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --prod"
It would be contained in the scripts object along with the other scripts available - e.g.:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"prod": "node --max-old-space-size=4096./node_modules/@angular/cli/bin/ng build --prod"
}
And you run it by calling npm run prod
(you may need to run sudo npm run prod
if you're on a Mac or Linux).
Note there may be an underlying issue which is causing Node to need more memory - this doesn't address that if that's the case - but it at least gives Node the memory it needs to perform the build.
Upvotes: 13
Reputation: 16820
I lost some days with this problem.... until I found that in some file I was importing one static file, a built file. It make the build to never end. Something like:
import PropTypes from "../static/build/prop-types";
Fixing to the real source solved all the problem.
Sharing my solution. :)
Upvotes: 2
Reputation: 1956
To solve this issue you need to run your application by increasing the memory limit by using the option --max_old_space_size
. By default the memory limit of Node.js is 512 mb.
node --max_old_space_size=2000 server.js
Upvotes: 47