无法“nvm 安装 8.0.0”

Rou*_*ndy 3 node.js nvm gulp macos-big-sur

我的目标是安装节点版本 8 ,以便我可以在项目上运行Gulp 。

我正在开发一个旧项目,该项目已被忽视并由另一位开发人员传给了我。我被告知可以通过安装 Node 版本 8 并在 package.json 文件中声明节点版本来使用 Gulp。

但是每当我尝试运行时nvm install 8都会收到错误error: "unsupported ARM architecture"

我的系统是MacOS Big Sur M1 芯片

我不太确定我应该在这里做什么。请帮忙!

Rou*_*ndy 10

解决方案

解决方案是将我的 shell 架构从 arm64 更改为 x86。

配备 M1 芯片的 Mac

2021 年 1 月:Apple 新款 M1 芯片(arm64 架构)没有 15.x 之前版本的预编译 NodeJS 二进制文件。

您可能会遇到的一些问题:

  1. 使用 nvm 安装 v14.15.4:
  • C代码编译成功
  • 但使用时会因内存不足错误而崩溃
  • 增加节点可用的内存仍然会产生内存不足错误:$ NODE_OPTIONS="--max-old-space-size=4096" ./node_modules/.bin/your_node_package
  1. 使用nvm安装某些版本时编译失败

此问题的一种解决方案是将 shell 的体系结构从 arm64 更改为 x86。

我们假设:

  • 您已经使用 nvm 安装了版本 12.20.1 和 14.15.4
  • 当前使用的版本是14.15.4
  • 您正在使用 zsh shell
  • 您已安装 Rosetta 2(首次打开仅限 Intel 的非命令行应用程序时,macOS 会提示您安装 Rosetta 2,或者您可以使用 softwareupdate --install-rosetta 从命令行安装 Rosetta 2)
//# Check what version you're running:
$ node --version
v14.15.4
//# Check architecture of the `node` binary:
$ node -p process.arch
arm64
//# This confirms that the arch is for the M1 chip, which is causing the problems.
//# So we need to uninstall it.
//# We can't uninstall the version we are currently using, so switch to another version:
$ nvm install v12.20.1
//# Now uninstall the version we want to replace:
$ nvm uninstall v14.15.4
//# Launch a new zsh process under the 64-bit X86 architecture:
$ arch -x86_64 zsh
//# Install node using nvm. This should download the precompiled x64 binary:
$ nvm install v14.15.4
//# Now check that the architecture is correct:
$ node -p process.arch
x64
//# It is now safe to return to the arm64 zsh process:
$ exit
//# We're back to a native shell:
$ arch
arm64
//# And the new version is now available to use:
$ nvm use v14.15.4
Now using node v14.15.4 (npm v6.14.10)
Run Code Online (Sandbox Code Playgroud)

来源: https: //github.com/nvm-sh/nvm