-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Mac M1 Arm, and architecture override #2743
Comments
node itself doesn’t support arm below v16, except with Rosetta, afaik. If this is incorrect, the exact version logic can be tweaked. I’m not sure why compiling it would be better than using a Rosetta binary? |
From what we have seen node14 and up support arm, or at least works out of the box. Early versions of node14 had some issues with memory while running node in chromium (electron) and were crashing hard, but that was fixed in minor version and compiled binary is native arm one and works great. The problem for us is that we are running Electron application with Realm database. Electron supports arm64 out of the box. Realm requires native binaries that are the same arch as Electron. While installing Node14 from source, or Node15 as well, the binary that comes out is arm64 binary:
If you try to install the same version from binary, because of NVM overriding the arch variable, the x86_64 version is being installed. Sounds good, it should work with Rosetta, and that being partially true, most of things do work ok. In out case however, the Electron was starting, and then our main app was throwing error that Realm requires arm64 binaries, and got x86_64 instead. I believe it was due to node, and hence npm/yarn to install wrong binaries for Realm.
The problem then sums up to: some tooling takes the arch of the system, and some other tooling takes the arch of the node process and mess occurs. Seems that compiled version of node 14.x and 15.x do support M1 ARM |
This installation behavior did change on version 0.39.1, so if you need to compile from source, you can use this installation command, here I'll use lts/erbium as an example: nvm install -s lts/erbium |
Yes, we switched to use -s flag for now, but the behaviour in my opinion is just wrong, and it should not override the architecture for nodes below 14.x as these versions have ARM support merged there, even though the binaries are not provided. |
I have recently learned that node ^14.17 (not all node 14s, and not node 15) can be compiled in a non-rosetta M1 env, even though binaries are provided only for 16+. nvm should thus not alter the architecture for ^14.17 either. |
As previously mentioned, all the node starting from 14.x and up do support M1 already, that's my whole point :) |
@bartoszhernas the node release team claims that only node 14.17+ in the 14 line actually supports it. |
Ahh, ok :) |
So what's the appropriate way to install it on Mac m1? The readme script and instructions still install intel version (node 16) |
Is there a command that could instruct nvm to install arm version of Node V16.xx? I currently have the machine set up to use Rosetta compiled version. |
@fyun89 i believe if you're in a non-Rosetta terminal it should Just Work for node 16+ - make sure you're on the latest version of nvm. |
I would love an -arch flag. Basically I am in arm64 zsh, I set arch to x86, but my node (via nvm) is still an arm binary, so process.arch is arm64 for node. I would love to just:
And it just switches my current default lts v16.16.0 to the x86 binary. I would LOVE this. Maybe I can go spelunk in my nvm script to try to add this myself... edit I couldn't even find the script that nvm runs from (which nvm just returns a literal bash script not the file path)...so I ended up using Rosetta |
@crisdosyago it’s an OS limitation, so I’m not sure how nvm would be able to accomplish that. |
@ljharb my model was it was as simple as: nvm-internal-stuff.sh:
But I don't know anything about this 🙂 ¯\_(ツ)_/¯ |
I believe that won't allow the binary to compile (if needed) nor to run. Certainly if there's a way for nvm to make this easier, I'm all for it, but I think M1 owners just have to "know" to switch to Rosetta for non-M1-compatible versions of any application. |
So in my rosetta zsh in ~/.nvm/versions/node just now I: cris@-MacBook bin % ./node -p process.arch
x64
cris@-MacBook bin % arch
i386
cris@-MacBook bin % cd ../../v16.16.0/bin
cris@-MacBook bin % ./node -p process.arch
arm64 (because I had installed v16 when in regular shell, and install v18 when in rosetta), then in non rosetta zsh i: cris@-MacBook node % cd v16.16.0
cris@-MacBook v16.16.0 % cd bin
cris@-MacBook bin % arch
arm64
cris@-MacBook bin % ./node -p process.arch
arm64
cris@-MacBook bin % cd ../../v18.7.0/bin
cris@-MacBook bin % ./node -p process.arch
x64 To me, I don't know anything about this, but it looks like both binaries (arm and x64) both run in both shells (rosetta and normal), and I just thought, maybe there's some way to say: cris@-MacBook ~ % nvm use v16.16.0-arm64
Now using that other guy
cris@-MacBook ~ % node -p process.arch
arm64
cris@-MacBook ~ % nvm use v16.16.0-x64
Now using that guy
cris@-MacBook ~ % node -p process.arch
x64 ¯\_(ツ)_/¯ Like I said, I don't know, but it seems cool 🙂 |
thanks for addressing this issue! sharing what I did to get node v14.17.5 working on m1 without rosetta:
examples of log warnings:
|
Here is the solution I've found https://devzilla.io/using-nodejs-14-with-mac-silicon-m1 |
No, this installs the AFAIK there is still no easy way to install an arm64 version of node14 |
I was using a system with x64 architecture, but when I installed Node 18 using NVM (Node Version Manager), it mistakenly installed the arm64 version. This mismatch could potentially cause issues. To resolve this, I opted for a manual approach since NVM couldn't provide the x64 version of Node 18 that I needed. I visited the Node.js distribution page at https://nodejs.org/dist/v18.19.0 and manually downloaded the appropriate version. After downloading, I copied the contents into the '~/.nvm/versions/node' directory and renamed the folder to 'v18.19.0' to align with the naming convention. This allowed me to continue using NVM as my default tool for switching between Node versions. |
For anyone following this issue, there is a good answer for how to do this in another issue: #2350 (comment) # first run this to switch architectures
arch -x86_64 zsh
# then install
nvm install v14.21.3 |
Hi,
I have used NVM just when the M1 processors came out. Back then the NVM was returning 404 on binary download and then compiling node by itself. This was not ideal (built binaries would be better) but still ok.
Fast forward to now, rest of my team got the M1 macbooks, they followed my steps of nvm and node installation. We are still on v14, because v15 is not supported by some of our packages, and v16 is not working with Realm.
Imagine my surprise when their environment does not work. We pinpointed the issue to them having x86 node binaries, instead of arm64 ones (as me and our M1 CI has had for months now).
After day of searching for the issue, and not understanding why even the 15.3 which is officially supported arm version of node is not properly installing.
Only then I have found out the culrpit: NVM is overriding architecture for any Node version below 16.
I would vote to remove this as this is hidden, unintended side-effect and changes previous behaviour. In my opinion if I want to install 15.3 and you cannot find binaries, it's better to compile it on device instead of returning me a wrong binary (Intel one).
The text was updated successfully, but these errors were encountered: