There was a message recently on the Yocto mail list about running out of memory during building nodejs:
https://lists.yoctoproject.org/g/yocto/topic/93931877#58166
@khem has provided the guideline that you need 2GB per CPU core. With Intel and AMD cores which have hyperthreading, your effective core number is typically 2x the physical cores. So, for a 4 core CPU, you’ll need at least 16GB of RAM, and preferably 32GB. Where people run into problems typically is building on dual core servers where they might have 12 cores (24 virtual cores). In this case you need at least 48GB of RAM.
You can lessen the number of parallel build processes for a package which limits memory use:
PARALLEL_MAKE:pn-nodejs = "-j 8"
We also have some documentation on this: