如何修复 npm 安装在一个文件夹中失败并显示“发生未知的 git 错误”,但在另一个文件夹中可以正常工作

如何修复 npm 安装在一个文件夹中失败并显示“发生未知的 git 错误”,但在另一个文件夹中可以正常工作

我的服务器在 Centos 8 上运行,并且我安装了最新的 nodejs(v14.17.5)和 NPM(v7.21.0),但两者都没有 .git 文件夹。

我有一个非常奇怪的问题,如果我转到文件夹 example1.com,并运行 npm install,我收到以下错误,

[root@www centos]# cd /var/www/example1.com/httpdocs/
[root@www chat]#  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 ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://[email protected]/Defipoolhub/node-time.git
npm ERR! [email protected]: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-08-23T10_03_50_797Z-debug.log

但是,如果转到不同的文件夹、相同的服务器和相同的 package.json,我就不会遇到任何问题,怎么会这样呢,

[root@www centos]# cd /var/www/example2.com/httpdocs/
[root@www chat]#  npm install

up to date, audited 224 packages in 3s

4 packages are looking for funding
  run `npm fund` for details

4 vulnerabilities (2 low, 2 high)

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

关于如何调试此问题的任何想法,我已禁用 SELinux,但并未解决问题。

答案1

我遇到了类似的问题,尽管在 git 命令错误之后它说无法写入或创建 tmp 目录。我使用 Ubuntu,这对我有用(不确定这是否是一个干净的解决方案,说实话我只需要它工作几天)

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm install --unsafe-perm=true --allow-root

希望这可以帮助!!

相关内容