Ion*_*zău 0 git github node.js
根据文档,我们可以将git存储库用作NPM依赖项:
Git网址可以采用以下形式:
Run Code Online (Sandbox Code Playgroud)git://github.com/user/project.git#commit-ish git+ssh://user@hostname:project.git#commit-ish git+ssh://user@hostname/project.git#commit-ish git+http://user@hostname/project/blah.git#commit-ish git+https://user@hostname/project/blah.git#commit-ishcommit-ish可以是任何标签,sha或分支,可以将其作为git checkout的参数提供。默认值为
master。
很好,对于公共存储库,它就像一种魅力。对于私有存储库(例如来自GitHub的存储库),我尝试了以下操作:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"builder": "git+ssh://github.com/IonicaBizau/myprivatemodule.git"
},
"author": "",
"license": "ISC"
}
Run Code Online (Sandbox Code Playgroud)
当我npm安装,我得到下面的输出:
$ npm i
npm WARN package.json test@1.0.0 No description
npm WARN package.json test@1.0.0 No repository field.
npm WARN package.json test@1.0.0 No README data
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git Cloning into bare repository '/home/....'...
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git Permission denied (publickey).
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git fatal: Could not read from remote repository.
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git Please make sure you have the correct access rights
npm ERR! git clone ssh://github.com/IonicaBizau/myprivatemodule.git and the repository exists.
npm ERR! Error: Command failed: Cloning into bare repository '/home/...'...
npm ERR! Permission denied (publickey).
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.
Run Code Online (Sandbox Code Playgroud)
此错误仅针对私有存储库出现。
我可以git clone ...通过SSH 访问此存储库并进行工作。
这个问题有什么解决方案?
小智 5
就像在文档中说的那样,git url必须采用这种形式:
git+ssh://user@hostname/project.git#commit-ish
而且我认为需要通过ssh与用户一起访问github git,因此您的依赖项url应该为:
"git+ssh://git@github.com/IonicaBizau/myprivatemodule.git"