从 gitlab 私有仓库安装 npm 模块 [英] Install npm module from gitlab private repository

查看:30
本文介绍了从 gitlab 私有仓库安装 npm 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将 GitLab 用于我们的私人项目.有一些来自 github 的分叉库,我们想将它们安装为 npm 模块.直接从 npm 安装该模块是可以的,例如:

We are using GitLab for our private project. There are some forked libraries from github, that we want to install as npm module. Installing that module directly from npm is ok and for example this:

npm install git://github.com/FredyC/grunt-stylus-sprite.git

...也能正常工作,但对 GitLab 做同样的事情,只是改变域就会出现这个错误.

...works correctly too, but doing the same for GitLab, just changing domain gets me this error.

npm WARN `git config --get remote.origin.url` returned wrong result (git://git.domain.com/library/grunt-stylus-sprite.git)
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git Cloning into bare repository 'D:usersFredyAppDataRoaming
pm-cache\_git-remotesgit-git-domain-com-library-grunt-stylus-sprite-git-6f33bc59'...
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git fatal:unable to connect to git.domain.com:
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git git.domain.com[0: 77.93.195.214]: errno=No error
npm ERR! Error: Command failed: Cloning into bare repository 'D:usersFredyApp
DataRoaming
pm-cache\_git-remotesgit-git-domain-com-library-grunt-stylus-spr
ite-git-6f33bc59'...
npm ERR! fatal: unable to connect to git.domain.com:
npm ERR! git.domain.com[0: xx.xx.xx.xx]: errno=No error

从 GitLab 的 web 界面,我有这个 URLgit@git.domain.com:library/grunt-stylus-sprite.git.针对 npm install 运行它,它会尝试从 npm 注册表安装 git 模块.

From the web interface of GitLab, I have this URL git@git.domain.com:library/grunt-stylus-sprite.git. Running this against npm install it tries to install git module from npm registry.

但是使用 URL:git+ssh@git.domain.com:library/grunt-stylus-sprite.git 突然要我输入密码.我的 SSH 密钥不包含密码,所以我认为它无法加载该密钥.也许我错过了一些配置?密钥位于我的主目录中的标准位置,名称为 "id_rsa".

However using URL: git+ssh@git.domain.com:library/grunt-stylus-sprite.git is suddenly asking me for the password. My SSH key doesn't include passphrase, so I assume it wasn't able to load that key. Maybe there is some configuration for that I have missed ? Key is located at standard location in my home directory with the name "id_rsa".

我使用的是 Windows 7 x64.

I am on Windows 7 x64.

更新

从 NPM v3 开始,内置了对 GitLab 和其他来源(BitBucket、Gist)的支持,您可以从中安装软件包.不幸的是,它仅适用于公共的,因此与此并不完全相关,但有些人可能会觉得它很有用.

Since NPM v3 there is built-in support for GitLab and other sources (BitBucket, Gist), from where you can install packages. Unfortunately it works only for public ones so it's not exactly related to this, but some might find it useful.

npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]

查看文档:https://docs.npmjs.com/cli/install

推荐答案

您有以下连接到私有 gitlab 存储库的方法

You have the following methods for connecting to a private gitlab repository

使用 SSH

git+ssh://git@git.mydomain.com:Username/Repository#{branch|tag}
git+ssh://git@git.mydomain.com/Username/Repository#{branch|tag}

使用 HTTPS

git+https://git@git.mydomain.com/Username/Repository#{branch|tag}

使用 HTTPS 和部署令牌

git+https://<token-name>:<token>@gitlab.com/Username/Repository#{branch|tag}

这篇关于从 gitlab 私有仓库安装 npm 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆