React native max_old_space_size

Luong Truong
2 min readJan 25, 2019

--

Photo by Patrick Lindenberg on Unsplash

Talking about React native, there are plenty of great libraries out there which should be taken into account.

Following, my story begin when I was dealing with aws-sdk services and there is a javascript file that is 4.1MB or even greater now. I struggled for weeks to find out the solution to solve the problem we mentioned above.

max_old_space_size

What is max_old_space_size?

As far as I know, React native has to start a Node server for transforming javascript files to something else. Following, there much be a place to store things, right? Yes, and the size of that place is defined using… our friend: “max_old_space_size”.

Let’s understand it as simply as we can. If the size is too small, we do not have enough space to breath and we die. Our Node server behaves like that too.

Increase max_old_space_size

Now, let’s come to the most interesting part. The solution to increase space size.

Debug

Normally, when you type “react-native run-android” or “react-native run-ios” (or simply press the button build on Xcode), the Node server will be start automatically. However, in this case, we have to start the Node server manually by using:

node — max-old-space-size=8192 node_modules/react-native/local-cli/cli.js start

Now, you have the Node server running with space size 8GB.

You can replace the number “8192” by any number you like.

The rest is just run the app as normal and enjoy.

Release

Android:

Inside your app/build.gradle, add the following:

nodeExecutableAndArgs: [“node”, “ — max-old-space-size=8192”]

iOS:

From your project in Xcode, move to “Build Phases”. Inside “Bundle React Native code and images”, use this:

Note that build release will take a lot of time, it takes my Mac mini 2011 around 30 minutes to complete the build. So please, be patient.

Conclusion

Increase the max_old_space_size can solve the problem. However, we should pay attention in our laptop or desktop RAM before increasing it. If you have 16GB RAM, 8GB space size would be safe. If you have 8GB RAM, then try the lower space for safe.

Happy coding and hope you guys enjoy it!

--

--

Luong Truong

Working as a mobile developer who always challenge myself to become better everyday. “If you only do what you can do, you will never be more than you are now.”