Published on

Updating the Node architecture on MacBook Pro Silicon

Last Modified on
Last modified on
Authors
Updating the Node architecture on MacBook Pro Silicon
Photo by Christian Perner on Unsplash

Yesterday I purchased a new Silicon MacBook Pro 16 inch, 2021 with an M1 Max Chip. I had some software to update/refactor on my MacBook Pro since I had migrated from an older Intel MacBook Pro (late 2015). I successfully re-installed Homebrew, but when I started to work on my Next.js driven business site (this site), I got the following error:

zsh: bad CPU type in executable: node

I researched how to fix the issue. It is very easy to fix, as long as you know HOW to fix it. I found a thread on stackoverflow.com called zsh: bad CPU type in executable: node. I found it very quickly because those were the exact words I used to find my solution when conducting my Google search!

Indeed, it wass a CPU related issue that occurs on macOS Silicon when you have migrated your content from a macOS Intel.

The one (and accepted) answer there stated that I needed to update the Node version architecture on NVM. And I do use NVM to install different versions of Node.js! According to the answer there, I had to run the following command in Terminal:

softwareupdate —install-rosetta

According to the NVM docs on Github regarding M1 troubleshooting,

Experimental support for the M1 architecture was added in node.js v15.3 and full support was added in v16.0. Because of this, if you try to install older versions of node as usual, you will probably experience either compilation errors when installing node or out-of-memory errors while running your code.

I am (and was) running Node version 16.17.0, so errors regarding older versions of Node.js itself did not apply! But the older version of MacBook Pro with the Intel Chip was also applicable to such an error. So that is why I had to run the command softwareupdate --install-rosetta.

So “how will a M1 Mac know to use Rosetta for a version of node compiled for an Intel chip?”.

If an executable contains only Intel instructions, macOS will automatically use Rosetta to translate the instructions.

There is other information regarding migrating from Intel macOS to Silicon macOS Node installations, but what I am sharing here fixed the problem for me!

The NVM documentation on Github also showed how one could check to make sure that the architecture has been corrected for macOS Silicon by running the following command in Terminal:

node -p process.arch

And for me, the following was returned in Terminal:

x64

Which is exactly what should be returned if the NVM architecture has been corrected for macOS Silicon!