I have 512MB RAM machine with 512MB of swap memory available (basically it is heroku 7$ tier). Total is 1GB. My npm build takes 1.5 GB of RAM locally (npm build exits with MemoryError on heroku), I don't want to include /build folder into git and run builds locally. What are workarounds for this? Maybe any node flags?
Asked
Active
Viewed 503 times
4
-
Out of curiosity, what package are you building that takes so much memory? I assume there are some native binaries being compiled? Can you pre-compile them elsewhere? – Brad Dec 29 '20 at 22:46
-
I believe that my three biggest packages are ant-design, Monaco Editor and react. No, also no native binaries compilation – JaktensTid Dec 29 '20 at 22:48
-
What specifically does your build script run? – Brad Dec 29 '20 at 22:57
-
1@Daniel_Knights I mean 1.5 GB of RAM, not disk space of built libs – JaktensTid Dec 30 '20 at 12:29
-
@Brad I am not so strong in webpack and etc. I have a react-create-app application with craco for extending some of webpack configs. I.e I have default react-create-app config + craco plugin + monaco editor plugin. That's it what I have in my configuration. – JaktensTid Dec 30 '20 at 12:30
-
Does webpack have something like multi-step build to split entire build on chunks with less memory consumed? Or there is a way to force limit of memory without exiting the process? – JaktensTid Dec 30 '20 at 12:34
1 Answers
1
you can increase your ram to get server working via swap memory (with at least 2GB to get webpack working)
Example with a 4.3 GB swap:
sudo dd if=/dev/zero of=/swapfile bs=128M count=32
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
After that your server will have 4.3GB more ram (stored at hard drive and used virtually as ram)
To use the swap (and increase the ram) at every machine start, add it at /etc/fstab
/swapfile swap swap defaults 0 0
For more information about swap creation and configuration: https://linuxize.com/post/create-a-linux-swap-file/