I received a new MacBook Air with M1 at my workplace. Apparently Node on M1 macOS doesn’t work well except on version 15.3.0 or above where they fixed related issues, and all my projects are based on Node 12 ~14. I was using Mac with Intel chip before so this has taken much longer to solve than it should have.. albeit lesson learned.
ERROR: wasm code commit Allocation failed - process out of memory
Solution 1 – Change node to run on x64
$ node
Welcome to Node.js v12.21.0.
Type ".help" for more information.
>
> process.arch
'arm64'
By looking through installed Node information, you can see which architecture the node binary is build for, and in my case it was arm64. Apparently this is where many of the issues arise from, on Node@12 built for arm64. So manually switching from arm64 to x64 solved my error.
$ nvm uninstall <installed node version>
$ arch -x86_64 zsh
$ nvm install <wanted node version>
$ nvm alias default <wanted node version>
Solution 2 – Use Rosetta-Terminal
Uninstall nvm and duplicate terminal app as “Rosetta-Terminal”, configure its settings to “Open using Rosetta”. Reinstalling nvm using this terminal will install node under Rosetta and it allows apps build for Intel chip to work with Apple Silicon.
Solution 3 – Upgrade your node version
I know many times this isn’t a viable solution for an ongoing project, especially as of now when the lts version is still at 14. But this is the ultimate fix to the M1 node compatibility issue.
nvm uninstall <installed version>
nvm install 15.3.0