私人仓库,git 克隆成功,npm 安装失败

Private repo, git clone succeeds, npm install fails

我有一个私有的 Bitbucket 存储库。 Git克隆成功:

git clone git@bitbucket.org:user/repo.git

它找到我的 SSH 密钥设置 (~/.ssh/config),要求输入密码(实际上它不识别 Pageant,但我认为它不应该)并且一切运行顺利。普通SSH测试也ok:

> ssh -T git@bitbucket.org

这被重定向到 putty,它找到了 SSH 配置、Pageant 中的密钥并顺利登录。如果我使用 Git 的内部 ssh.exe 然后它找到密钥但不是 Pageant 所以我必须手动输入密码然后一切都很好。

然而,npm install 失败(省略了一些细节):

> npm i git+ssh://git@bitbucket.org/user/repo.git
npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config --get remote.origin.url
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:213:12)
npm WARN addRemoteGit     at emitTwo (events.js:87:13)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:172:7)
npm WARN addRemoteGit     at maybeClose (internal/child_process.js:827:16)
npm WARN addRemoteGit     at Socket.<anonymous> (internal/child_process.js:319:11)
npm WARN addRemoteGit     at emitOne (events.js:77:13)
npm WARN addRemoteGit     at Socket.emit (events.js:169:7)
npm WARN addRemoteGit     at Pipe._onclose (net.js:475:12)
npm WARN addRemoteGit  git+ssh://git@bitbucket.org/user/repo.git resetting remote C:\... because of error: { [Error: Command failed: git -c core.longpaths=true config --get remote.origin.url
npm WARN addRemoteGit ]
npm WARN addRemoteGit   killed: false,
npm WARN addRemoteGit   code: 1,
npm WARN addRemoteGit   signal: null,
npm WARN addRemoteGit   cmd: 'git -c core.longpaths=true config --get remote.origin.url' }
npm ERR! ... Cloning into bare repository 'C:\...'...
npm ERR! ... Permission denied (publickey).
npm ERR! ... Could not read from remote repository.
npm ERR! ... Please make sure you have the correct access rights
npm ERR! ... and the repository exists.
npm ERR! Windows_NT 6.3.X
npm ERR! node v4.4.0
npm ERR! npm  v3.8.1

如果我克隆存储库然后 npm install 在克隆的目录中那么一切都很好 - 所以这也不应该是问题。 (太长的路径我猜也不是问题。)所以,你没用?

这似乎是一个问题:https://github.com/npm/npm/issues/11567 + 进一步链接的问题。

我不知道他们是否会解决这个问题,因为私人 NPM 托管是他们的事...

;TLDR

(Windows OS 问题) 手动删除 %appdata%\Roaming\npm-cache

我有类似的错误。我尝试的一件事是 npm 缓存清理,它使用了很多 CPU 而从来没有 "finished"。所以我去了 %appdata%\Roaming\npm-cache 并试图删除,我不能。

我必须右键单击文件夹 >> 属性 >> 安全 >> 高级 >> 权限选项卡 我点击了我的用户名,然后我检查了 "Replace all child object permission entries...",然后点击了应用。

出于某种原因,我的 git 缓存中的遥控器在安全选项卡下没有权限。在此之后我的 npm install 工作了。

尽管问题是关于 Bitbucket 的,但我认为 Github 遇到的问题但具有完全相同的跟踪可以帮助您解决问题。

对我来说,仅更改 url 并没有使它起作用。以下是我必须采取的解决此问题的步骤:

  • git+ssh://git@github.com:owner/repo.git#master
  • 创建部署密钥并将其添加到存储库
  • 编辑 git 配置(~/.ssh/config 如果文件不存在则创建该文件)以强制使用 DeployKey 而不是默认的 ssh 密钥。 (请务必在 ssh 配置文件中引用部署密钥的私钥部分)

之后 npm install 就可以正常工作了。 npm 安装中断导致的所有其他选项和解决方案

我在 Windows 上的解决方案:

  • 使用条目
  • 创建git配置文件C:/Users/<username>/.ssh/config
Host bitbucket.org
     IdentityFile ~/.ssh/bitbucket_key
     IdentitiesOnly yes
  • 将 openssh 私钥保存在 C:/Users/<username>/.ssh/bitbucket_key
  • 为了防止打开询问凭据的弹出窗口,我必须像这样编辑 git 配置文件 C:/Users/<username>/.gitconfig
[credential]
    helper = manager
    interactive = false
    modalPrompt = false

此解决方案也适用于 VS Code 控制台,但您必须在凭据弹出窗口出现时将其取消(我还没有找到禁用它们的方法)。