How to increase Javascript heap size for Ionic - node.js

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. :)
Ionic Info:
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

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.

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

Related

"Cannot find plugin.xml for plugin kapsel-plugin-i18n. Please try adding it again." when I'm trying to install kapsel-plugin-i18n for iOS 15 (local)

Do you know which version of kapsel-plugin-i18n might work with iOS 15 ?
Which version of npm and node might fit with Cordova 9.0.0 ?
Indeed, I had to upgrade the Kapsel plugins for my application to fit with iOS 15 but there is an error when I try to install the kapsel-plugin-i18n. (which comes from the SDK 3.2 SP04 PL1).
"Cannot find plugin.xml for plugin kapsel-plugin-i18n. Please try adding it again."
But the plugin.xml is here, in the local directory.
For information, I'm using :
Cordova 9.0.0
npm 6.14.15
node : 14.18.0
Mac OS Big Sur (11.6)
The command line I'm using is :
sudo cordova plugin add kapsel-plugin-i18n --searchpath /Absolute path to plugin local directory/.
Thank you for your answer.
Kat
As per the git repo :
Security holding package
This package contained malicious code and was
removed from the registry by the npm security team. A placeholder was
published to ensure users are not affected in the future.

Windows 10 - node: could not initialize ICU (check NODE_ICU_DATA or --icu-data-dir parameters) error

An issue similar to this post: node: could not initialize ICU (check NODE_ICU_DATA or --icu-data-dir parameters)
I get the same error message:"node: could not initialize ICU (check NODE_ICU_DATA or --icu-data-dir parameters" with the fresh node installation. It is a brand new computer with Windows 10 Pro system version 10.0.17763 Build 17763. I have tried installing version 10.16.0 LTS and version 12.6.0 current from node.js website. In both cases I have exactly the same error, does not matter if I run as admin or a normal user. I cannot use the solutions described above as npm will not run (same error). I have no idea what to do next.
I managed to sort it out. As it turns out, other software was using the environment variable: NODE_ICU_DATA. I have removed NODE_ICU_DATA variable, restarted computer and installed node again. It is working fine now.

Building react native project on xcode takes for ever (very slow) on the process Running 1 of 1 custom shell script

It seems a strange behavior. I have zsh and for development I use nvm
But I also seem to have node installed by brew.
The packager runs but the xcode appears to wait till the packager is ready but It is already!
So I take more than 20 minutes !!
When it used to be very fast.
Not sure if it is watchman, node version, bash. Or something else. But it is driving my crazy,
Hope you could help me find a solution.
Versions:
react-native-cli: 2.0.1
node --version
v6.11.2
What version of node is recommended to work with React Native?
Have you tried clearing your caches within Xcode?
How to Empty Caches and Clean All Targets Xcode 4
Other than that have you ensured your PATH is setup properly with the version of react-native you're trying to execute?

Electron throwing error %1 is not a valid win32 application with custom node addon

I've written a custom node addon that works perfectly fine when running the 64 bit version of Electron.
I tried setting the architecture to ia32 and everything builds, but I get the not valid win32 application error, no matter what I do.
My environment settings are:
npm_config_disturl=https://atom.io/download/atom-shell
set npm_config_target=1.0.1
set npm_config_arch=ia32
set npm_config_runtime=electron
set HOME="C:\Users\myHome\.electron-gyp"
set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
I have been building the addon by calling npm install.
Here's how I set my node to target 32 bit and install all packages in 32bit format. It works for me. You may try.
npm set npm_config_arch ia32
npm clean-install --arch=ia32
The first command set the node environment to 32bit.
The second command re-install all the node packages that are 32bit compatible.
I was trying to compile for windows from mi Mac and I had that problem too, but after some readings I figured out how to proceed, and after all I can say that I got it. Yesterday I spent all day setting up a windows virtual machine in my (other) Linux laptop (I used my linux laptop just because my mac was exhausted in storage...). I was having too a problem with the preloadScript from electron main process in windows, Cant found the script, it was solved too.
Anyway, I think the library node printer from #tojocky is well maintained, in other hand in the electron-builder documentation they say that you should compile in native for natural reasons. Once you will have it, you'll see that it's a cleaner and pragmatic solution ...
This was my entire process, I hope it helps to someone having the same issue:
Get VirtualBox (or Parallels but is not free)
Get iso for W10
Create a VM with this W10 iso, and you should give to this VM some storage (because some dependency that you'll need to compile), I have assigned 60gb to this VM
Once I had that VM running, I just installed in that machine Visual Studio 2017 (with their build-tools included, it's necessary)
And then, I used CMD to make the rest
Install NodeJS (and NPM, but it comes with)
Install node-gyp globally
Install Python 2.7
Clone your project from git (in my case)
npm i (in your project), you should have as npm dependency in your package.json the module electron-builder of course. (here I had some troubles because when node-gyp tried to rebuild printer to generate the binary for windows it was failing, this was because it was imposible to find the python executable, so if you face this problem you should add it like:npm config set python "c:\Python27\python.exe" in my case )
Then try again npm i and Voila!
After all, you should make the build using electron-builder, in my case my npm script command was build --win --x64 but you can use the --ia32 flag as well for 32bits

How to install latest ionic2 components

I am currently using ionic2 to try creating a cross plattform app. I know that ionic2 still is under heavy construction and that things (may) change at any time.
Still i wonder how I could install the latest components/api stuff from the nightly builds (or whereever they reside).
I am especially referring to the infiniteScroll Component that is mentioned in the API-Documents of ionic2.
Since i don't understand the layout of the components inside my project fully, i checked where i could see some of them in the directory structure. If i get this right, they all reside in <projectHome>/node_modules/ionic-framework/components?
At least lots of the components mentioned in the documentation above are listed there.
But as i can't find the infiniteScroll Component there, i would like to get some hints on how to install this (and the other missing ones) either by directly giving the respective commands or by pointing to appropriate documentation (i simply did not find anything although searched quite a while for it).
ionic info shows:
Your system information:
Cordova CLI: 6.0.0
Ionic Version: 2.0.0-beta.1
Ionic CLI Version: 2.0.0-beta.17
Ionic App Lib Version: 2.0.0-beta.8
ios-deploy version: 1.7.0
ios-sim version: 4.1.1
OS: Mac OS X El Capitan
Node Version: v5.6.0
Xcode version: Xcode 7.0 Build version 7A220
Sir,
Ionic made some changes in their latest commit. You could see the changes here in the changelog. (Mar 1)
The components are not present in 'ionic-framework/ionic' anymore and they are now present in 'ionic-angular'.
Infinite scroll was added in the release 2.0.0-beta.2, whereas you use the previous release 2.0.0-beta.1 So you might not be able to add it. You could change your package.json to reflect the latest version like shown below.
"ionic-angular": "2.0.0-beta.2",
I would recommend you to read the changelog as it would give a better idea. Hope this was helpful. Thanks.

Resources