【问题标题】:Having trouble installing npm on mac M1在 mac M1 上安装 npm 时遇到问题
【发布时间】:2021-10-24 01:05:57
【问题描述】:
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

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

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

【问题讨论】:

  • 什么版本的节点?
  • 另外,M1 肯定存在一些 bcrypt 问题:github.com/kelektiv/node.bcrypt.js/issues/868 等。您是否安装了构建工具(xcode-select)等?
  • 我的node版本是v16.6.0,我有VS Code和WebStorm,可以帮忙吗?

标签: node.js macos npm npm-install


【解决方案1】:

我找到了解决方案,我只需要将架构添加到节点,

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

【讨论】:

    【解决方案2】:

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

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

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
    

    然后,运行以下命令:

    arch -x86_64 zsh 
    

    【讨论】:

    • 超级有帮助,效果很好
    【解决方案3】:

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

    我们使用的是 Nodejs v16.13.1。运行 arch -x86_64 zsh 后,npm 安装仍然失败 (Error: Cannot find module 'node-darwin-arm64/package.json')。

    arch 返回i386

    对我们来说关键是重新安装 Nodejs(通过 nvm,nvm use v16.5.0 &amp;&amp; nvm uninstall v16.13.1 &amp;&amp; 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
    

    【讨论】:

      【解决方案4】:

      似乎重新安装旧版本的 NodeJS(和 NPM)对我有所帮助。 从here 尝试版本14.18.3

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-08
        • 2022-07-02
        • 2020-06-05
        • 2021-06-08
        相关资源
        最近更新 更多