Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macbook Pro M1 Error: "Failed to setup node binary." #182

Closed
lidefang0918 opened this issue Jan 11, 2021 · 9 comments
Closed

Macbook Pro M1 Error: "Failed to setup node binary." #182

lidefang0918 opened this issue Jan 11, 2021 · 9 comments

Comments

@lidefang0918
Copy link

Install nvs in M1 success, but it dosn't work.
run any nvs command, throw the errorMessage as below:

MacBook-Pro ~ % nvs -v
Downloading bootstrap node from https://nodejs.org/dist/v12.18.4/node-v12.18.4-darwin-arm64.tar.xz
-#O#- # #
Failed to setup node binary.
MacBook-Pro ~ %

@jasongin
Copy link
Owner

jasongin commented Jan 11, 2021

Node.js does not yet publish builds for the Apple M1 (arm64), and when they do it will be for node v15 or later. It's possible to build binaries from source, but nvs does not support that.

For now, the x64 binaries should work fine via Rosetta 2, though with non-optimal performance. Try this:

arch -x86_64 zsh
nvs

Once you use nvs to download node x64 builds from within that x64 shell, you should then be able to run node and use nvs to switch between versions from within a normal shell.

It could be possible to update nvs to handle this more automatically, by downloading and using x64 builds whenever an arm64 build is not available for the requested version. Unfortunately I don't have an M1 system available to develop and test on. So, PRs are welcome!

@jasongin
Copy link
Owner

See also nodejs/build#2474

@brody4hire
Copy link

See also nodejs/build#2474

Do you think this will lead to worse download sizes?

@jasongin
Copy link
Owner

jasongin commented Feb 3, 2021

Do you think this will lead to worse download sizes?

Based on the discussion in that issue about using fat binaries for the Mac OS builds starting in v16, yes I would expect the download on Mac OS to be larger then.

But meanwhile, nvs needs to be updated to automatically select x64 instead of arm64 when on Mac OS. That will work now (with the node v12 bootstrap download) and should continue to be correct even with node v16+, presuming the "fat binaries" are published as x64.

If anyone has an M1 Mac available to develop and test that fix on, a PR would be welcome!

micate added a commit to micate/nvs that referenced this issue Apr 8, 2021
based on issue jasongin#182, tested and it works.
jasongin pushed a commit that referenced this issue Apr 12, 2021
based on issue #182, tested and it works.
@jasongin
Copy link
Owner

Fixed by 22fe78a

@shadowspawn
Copy link

From Node.js v16 there are separate downloads available for x64 and arm64 on Darwin. Inspecting the node binary with lipo -archs confirms they contain a single architecture.

https://nodejs.org/dist/latest-v16.x/

By contrast, based on the file size and online comments during the development of the Apple silicon native support, I think the .pkg contains a fat binary. (I have not inspected it to actually confirm.)

@jasongin
Copy link
Owner

jasongin commented May 8, 2021

The change above was to fix the boostrap node binary download, which is not on v16 yet (and will not be for a while).

Separately from that, using nvs to install Node v16 should correctly select arm64 platform on Mac M1. I think that will require a small change in version.js here. I don't have an M1 Mac to test on - can someone else test and submit a PR?

@shadowspawn
Copy link

shadowspawn commented May 8, 2021

The change above was to fix the boostrap node binary download, which is not on v16 yet (and will not be for a while).

Sorry, I missed the distinction between the bootstrap download and the user requested download. Thanks for clarifying.

(I don't have an Apple silicon Mac.)

@ashsearle
Copy link
Contributor

For info: I hit a similar issue on a brand new machine (running macOS Monterey):

nvs:119: bad CPU type in executable: $HOME/.nvs/cache/node

I confirmed the node binary was x86_64, but I wasn't (yet) able to run any x86_64 executable:

arch -x86_64 zsh

arch: posix_spawnp: zsh: Bad CPU type in executable

It turns out Rosetta 2 wasn't installed. With GUI applications macOS would automatically detect this situation and prompt you to install it, but as I was installing things via CLI I didn't get any hints about this.

Resolution: explicitly install Rosetta via cli:

softwareupdate --install-rosetta

After installing Rosetta . "$NVS_HOME/nvs.sh" install worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants