Reputation: 5880
I am having an out of memory problem with running a build of an Ionic application with --release
and --prod
flag. Unfortunately, as it seams, the space of memory that Node is allowed to use is not sufficient for the process and it's producing the following error (probably after no memory blocks are available to carry out the operation):
As suggested in this answer, I tried to exploit the max_old_space_size
flag from the package.json
start
script before the build command to no avail. Mainly because the node process is run internally by the Ionic CLI way after the flag is set.
I also tried to re-install Ionic with a bigger heap size as suggested in this answer, but that seems to only address memory limitations during installation of the Ionic package itself, and not any subsequent operations with Ionic via the CLI.
Thanks in advance for any help. :)
cli packages: (D:\ionic\<...>\node_modules)
@ionic/cli-utils : 1.9.2
ionic (Ionic CLI) : 3.9.2
global packages:
Cordova CLI : 7.0.1
Gulp CLI : CLI version 3.9.1 Local version 3.9.1
local packages:
@ionic/app-scripts : 2.1.4
Cordova Platforms : android 6.2.3 ios 4.5.0
Ionic Framework : ionic-angular 3.3.0
System:
Android SDK Tools : 25.2.2
Node : v6.10.2
npm : 4.0.5
OS : Windows 7
Upvotes: 3
Views: 4639
Reputation: 4136
I flagged this as a duplicate, but in case anyone happens across it before it is consolidated, I posted the modern solution to this problem over at https://stackoverflow.com/a/48895989/4200039:
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 are permitted, which includes "--max_old_space_size".
So I put in my .bashrc: export NODE_OPTIONS=--max_old_space_size=4096
Upvotes: 0
Reputation: 5880
The only solution was to increase the memory size for Javascript heap internally (from Ionic's point of view) as and when the Ionic CLI kicks the process.
The post on Github by @timothybclayton on a similar issue under ionic-app-scripts helped me figure this out.
However, I had to do it in quite different way than that because I had Nodist as package manager for NodeJS. So, I had to go to the /bin
folder under Nodist installation directory and tweak the ionic.cmd
file.
This is how the ionic.cmd
file looks as it has now allows plenty of memory for NodeJS to carry out the process:
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=12288 "%~dp0\node_modules\ionic\bin\ionic" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=12288 "%~dp0\node_modules\ionic\bin\ionic" %*
)
Hope this helps anyone else with a similar issue, not only for Ionic, but for any other memory-intensive process with NodeJS.
Upvotes: 3