node.js 无法从 bitbucket repo 安装 npm
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24989694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot npm install from bitbucket repo
提问by Eugene Kostrikov
I'm trying to install a private package recently moved from github to bitbucket.
我正在尝试安装一个最近从 github 移到 bitbucket 的私有包。
npm install [email protected]:owner/repo.git
ends up with
结束于
npm http GET https://registry.npmjs.org/git
(note package in the url) with this error:
(注意 url 中的包)出现此错误:
npm ERR! notarget No compatible version found: git@'bitbucket.org:flyvictor/fortune-secruity.git'
错误!notarget 未找到兼容版本:git@'bitbucket.org:flyvictor/fortune-secruity.git'
(note a 'just after @)
(注意一个'就在 之后@)
I tried to escape @, wrap repo name in quotes, but always get same result.
我试图转义@,将回购名称用引号括起来,但总是得到相同的结果。
For github we use urls formatted as git://github.com/owner/repo#v.v.vand this works fine! But if I use same syntax for bitbucket npm just hangs doing nothing.
对于 github,我们使用格式为 的 url git://github.com/owner/repo#v.v.v,这很好用!但是如果我对 bitbucket npm 使用相同的语法,它就会挂起什么都不做。
Any idea?
任何的想法?
p.s. keys, access right and so one are correct. I can contribute to these repos, clone them with git, but not to npm install. Github packages that get installed well are also private.
ps 键,访问权限等等都是正确的。我可以为这些 repos 做出贡献,用 git 克隆它们,但不能用于 npm install。安装良好的 Github 包也是私有的。
回答by user1610694
npm install git+ssh://[email protected]/{user}/{repository}.git
回答by gztomas
npm install bitbucket:<bitbucketname>/<bitbucketrepo>
回答by sver
I tried a lot of ways but only this worked for me :
我尝试了很多方法,但只有这对我有用:
npm install -s https://bitbucket.org/owner/repo-name/commits/tag/0.1.0
回答by smacktrack
npm install ssh://[email protected]:{user}/{repository}.git
回答by Abraham Hernandez
Declaimer:As Eric Uldall said: this method is easy but it lacks security. You have now committed a password in plain text to your repository. That's how is working out lately for me, but not recommended.
声明:正如 Eric Uldall 所说:这种方法很简单,但缺乏安全性。您现在已将纯文本密码提交到您的存储库。这就是我最近的锻炼方式,但不推荐。
Straight from the npm Documentationfor the installcommand:
直接从NPM文件的install命令:
$ npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]
Example:
例子:
$ npm install bitbucket:mybitbucketuser/myproject
The Yarn documentationfor addas of today Feb 28, 2019 doesn't have support for git repositories.
该纱线文件为add今天的2019年2月28日没有对git仓库的支持。
The above example didn't work for me with private repositories, because you will need to generate a token to use it. How is that?
上面的示例不适用于我的私有存储库,因为您需要生成一个令牌才能使用它。那个怎么样?
Login to your Bitbucket account and under user settings add an app password:
登录您的 Bitbucket 帐户并在用户设置下添加应用密码:
Then you can add the dependency to your package.jsonas:
然后,您可以将依赖项添加到您的package.jsonas:
"dependencies": {
"module": "git+https://<username>:<app-password>@bitbucket.org/<owner>/<repo>.git"
}
or on your terminal type:
或在您的终端类型上:
npm install git+https://<username>:<app-password>@bitbucket.org/<repo-owner>/<repo>.git
Don't forget to replace:
不要忘记替换:
- username: with your username
- password: with your app password
- repo-owner: with the owner of the repo
- repo: with the repository name of the module
- 用户名:使用您的用户名
- 密码:使用您的应用密码
- repo-owner: 与repo 的所有者
- repo: 带有模块的存储库名称
回答by abmap
So in order to install npm package from remote git repository, you need to make sure
因此,为了从远程 git 存储库安装 npm 包,您需要确保
- You have git binary installed in your machine/virtual machine/container you're working on
- You have access to the repo, and I recommend you to use https instead of ssh for the protocol for the public repo because ssh protocol requires you to have ssh credentials.
- 您在您正在处理的机器/虚拟机/容器中安装了 git 二进制文件
- 您可以访问存储库,我建议您使用 https 而不是 ssh 作为公共存储库的协议,因为 ssh 协议要求您拥有 ssh 凭据。


