【问题标题】:Private repo, git clone succeeds, npm install fails私有仓库,git clone 成功,npm install 失败
【发布时间】:2016-06-29 22:08:53
【问题描述】:

我有一个私人 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

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

【问题讨论】:

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


    【解决方案1】:

    我在 Windows 上的解决方案:

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

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

    【讨论】:

      【解决方案2】:

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

      对我来说,仅更改 url 并不能使其正常工作。以下是我必须采取的步骤来解决这个问题:

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

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

      【讨论】:

      • 你使用npm install吗? (你在哪里使用 url?)这是在哪个操作系统上?
      【解决方案3】:

      ;TLDR

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

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

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

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-04-08
          • 2012-12-04
          • 1970-01-01
          • 2020-06-29
          • 1970-01-01
          • 2016-01-31
          • 2016-01-06
          • 2020-05-01
          相关资源
          最近更新 更多