Skip to content

Instantly share code, notes, and snippets.

@mcalthrop
Last active November 17, 2021 22:41
Show Gist options
  • Save mcalthrop/4618bcaa1b3cd3fe6bba1a9b8bb71b1c to your computer and use it in GitHub Desktop.
Save mcalthrop/4618bcaa1b3cd3fe6bba1a9b8bb71b1c to your computer and use it in GitHub Desktop.
Using Node with Apple's new M1 chip

Using NVM and node with Apple's new M1 chip

20 January 2021

Rationale

At the time of writing, there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple's new M1 chip (arm64 architecture).

Additional issues encountered:

  • when I used nvm to install the version I required (14.15.4)
    • it compiled the C code successfully
    • but crashed with an out of memory error
    • I tried increasing the memory available to node, but still got the oom errors:
      $ NODE_OPTIONS="--max-old-space-size=4096" ./node_modules/.bin/snowpack dev
  • when I used nvm to install other versions (I forget which ones now), the compilation actually failed

Instructions

Assumptions:

  • I currently have versions 12.20.1 and 14.15.4 installed using nvm
  • the current version in use is 14.15.4
# Check what version I'm running:
$ node --version
v14.15.4
# Check architecture of the `node` binary:
$ node -p process.arch
arm64
# Confirms that the arch is for the M1 chip, which is causing the problems.
# So I need to uninstall it.
# Can't uninstall the one I'm currently using, so switch to another version:
$ nvm install v12.20.1
# Now I can uninstall the version I want to replace:
$ nvm uninstall v14.15.4
# Set the architecture for my shell to 64-bit X86:
$ arch -x86_64 zsh

At this point in time, I'm still in the shell that is running using the M1 architecture.

So I now need to open a new terminal window in order to run my shell in the 64-bit X86 architecture.

# `node` will not be on the path in this new terminal window.
# So install it:
$ nvm install v14.15.4
# Now check that the architecture is correct:
$ node -p process.arch
x64

Credits

Original source: nvm-sh/nvm#2350 (comment)

The instructions in that GitHub issue comment didn't quite work for me, hence creating this gist to reflect what I found to work.

@hunthunthunt
Copy link

this is super helpful, thanks 👍

@mcalthrop-lego
Copy link

this is super helpful, thanks 👍

@hunthunthunt No worries!

The instructions above have made into the README:
https://github.com/nvm-sh/nvm/blob/master/README.md#macos-troubleshooting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment