在 mac M1 上安装 npm 时遇到问题

Nik*_*hil 17 macos node.js npm npm-install

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm WARN deprecated bcrypt@4.0.1: versions < v5.0.0 do not handle NUL in passwords properly
npm ERR! code 1
npm ERR! path /Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node
npm ERR! command failed
npm ERR! command sh -c node installArchSpecificPackage
npm ERR! npm ERR! code ETARGET
npm ERR! npm ERR! notarget No matching version found for node-darwin-arm64@16.6.1.
npm ERR! npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! npm ERR! notarget a package version that doesn't exist.
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/nikhil/.npm/_logs/2021-08-23T17_20_39_011Z-debug.log
npm ERR! node:internal/modules/cjs/loader:936
npm ERR!   throw err;
npm ERR!   ^
npm ERR! 
npm ERR! Error: Cannot find module 'node-darwin-arm64/package.json'
npm ERR! Require stack:
npm ERR! - /Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node/installArchSpecificPackage.js
npm ERR!     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
npm ERR!     at Function.resolve (node:internal/modules/cjs/helpers:100:19)
npm ERR!     at ChildProcess.<anonymous> (/Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node-bin-setup/index.js:18:27)
npm ERR!     at ChildProcess.emit (node:events:394:28)
npm ERR!     at maybeClose (node:internal/child_process:1067:16)
npm ERR!     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
npm ERR!   code: 'MODULE_NOT_FOUND',
npm ERR!   requireStack: [
npm ERR!     '/Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node/installArchSpecificPackage.js'
npm ERR!   ]
npm ERR! }

npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/nikhil/.npm/_logs/2021-08-23T17_20_39_074Z-debug.log

Run Code Online (Sandbox Code Playgroud)

我无法在我的 mac M1 上的项目存储库中安装任何包,已经删除了 node_modules 和 package-lock.json 并在之后尝试了 npm i 。

尝试运行 npm i, npm i 来处理单个软件包,但无法修复它,还尝试使用纱线安装,但我面临同样的问题。

Nik*_*hil 25

将架构添加到节点:

$ nvm uninstall 14
$ arch -x86_64 zsh 
$ nvm install 14
$ nvm alias default 14

Run Code Online (Sandbox Code Playgroud)


小智 12

Nikhil 提供的解决方案是一个良好的开端。不过这样更完整,适用于更多情况:

首先,安装nvm(Node版本管理器):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Run Code Online (Sandbox Code Playgroud)

然后,运行以下命令:

arch -x86_64 zsh 
Run Code Online (Sandbox Code Playgroud)


小智 7

我们的一位开发人员遇到了这个问题,他在 2021 年 12 月新买了一台 M1 笔记本电脑。ralphjsmit 的解决方案帮助我们解决了问题。

我们使用 Nodejs v16.13.1。运行arch -x86_64 zshnpm install 后仍然失败(Error: Cannot find module 'node-darwin-arm64/package.json')。

archi386

我们的关键是重新安装 Nodejs(通过 nvm,nvm use v16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1

如果我要总结我们运行的所有步骤,它们将是

> node -v
v16.13.1
> node -p process.arch
arm64
> arch -x86_64 zsh
> nvm use 16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1
nvm use 16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1
Now using node v16.5.0 (npm v7.19.1)
Uninstalled node v16.13.1
Downloading and installing node v16.13.1...
... 
# output here, I am not on an M1 machine, but it mentions x64 in the name of the node binary file
...
Now using node v16.13.1 (npm v8.1.2)
> npm install
Run Code Online (Sandbox Code Playgroud)