私有仓库,git clone成功,npm安装失败

时间:2016-03-14 18:06:27

标签: git ssh npm ssh-keys npm-install

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

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

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

> ssh -T git@bitbucket.org

这被重定向到putty,它找到SSH配置,Pageant中的键并且没有问题登录。如果我使用Git的内部ssh.exe,那么它会找到密钥而不是Pageant,所以我必须手动输入密码然后一切都很好。

但是,npm安装失败(省略了一些细节):

> 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

如果我克隆了repo然后克隆目录中的npm install,那么一切都很好 - 所以这也不应该是问题。 (太长的路径也不是我想的问题。)所以,你不工作吗?

3 个答案:

答案 0 :(得分:1)

虽然问题是关于Bitbucket,但我认为我在Github上遇到的一个问题,但完全相同的跟踪可以帮助您解决问题。

对我来说,只更改网址并没有让它发挥作用。以下是我必须采取的步骤来解决这个问题:

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

之后,npm安装工作正常。所有其他选项和解决方案都是由npm安装破坏产生的

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

; TLDR

(Windows操作系统问题) 手动删除%appdata%\Roaming\npm-cache

我有类似的错误。我试过的一件事是npm cache clean,它占用了大量的CPU并且从未“完成”。所以我去%appdata%\Roaming\npm-cache试图删除,我不能。

我必须右键单击文件夹&gt;&gt;属性&gt;&gt;安全&gt;&gt;高级&gt;&gt;权限选项卡 我单击了我的用户名,然后选中了“替换所有子对象权限条目...”,然后单击“应用”。

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