npm从私人gitlab安装git + ssh

时间:2018-07-11 13:31:09

标签: git npm

我有一个私人的Gitlab。那里有一个我从这个地址git clone的仓库:[git@10.15.8.210:8888]:recsystem/robotRecSystem.git

直到节点7.2.1(npm v3.10.10),我都可以这样安装:

$ npm install git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git --save
src@0.0.0 /home/pauloh/src/recsystem-web/src
└── robotRecSystem@1.1.0  (git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git#b589aa1d17cb44d5c17e5fd69929a7a8b64c9eba)

但是从节点8.9.0(npm v5.5.1)开始,当我使用同一命令得到错误时:

$ npm install git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git --save
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://%5Bgit@10.15.8.210/:8888]:recsystem/robotRecSystem.git
npm ERR! 
npm ERR! ssh: Could not resolve hostname 10.15.8.210/: Name or service not known
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! 
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pauloh/.npm/_logs/2018-07-11T13_00_48_101Z-debug.log

读取错误,调用命令git ls-remote时npm失败。 它尝试以下命令:

/usr/bin/git ls-remote -h -t ssh://%5Bgit@10.15.8.210/:8888]:recsystem/robotRecSystem.git

如果我将此命令更改为:

/usr/bin/git ls-remote -h -t [git@10.15.8.210:8888]:recsystem/robotRecSystem.git

所以,我认为问题是:

  • 我的网址字符串[git@10.15.8.210:8888]:recsystem/robotRecSystem.git不是普通的网址,因为它不是protocol://user@hostname:port/path
  • npm无法正确解析我的URL字符串。
  • npm正在将字符[更改为%5B,但它不起作用
  • npm是协议ssh://的前缀,并且不起作用

如何将我的网址字符串更改为npm才能正确解析?

1 个答案:

答案 0 :(得分:0)

npm install文档(https://docs.npmjs.com/cli/install)中的括号

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

仅表示不得使用此部分,并非意味着必须包括方括号...

因此,git+ssh://git@10.15.8.210:8888:recsystem/robotRecSystem.git似乎是您想要的。

OR

您可以使用GIT_SSH_COMMAND变量的定义来预先设置端口,以消除冒号可能引起的问题:

GIT_SSH_COMMAND='ssh -p 8888' git+ssh://git@10.15.8.210:recsystem/robotRecSystem.git

甚至更好

您可以按照https://www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client

中的说明在.ssh/config中定义端口。