如何直接从GitHub安装npm软件包?

尝试从GitHub安装npm模块时可能会遇到package.json的ENOENT错误。正确的方式是使用特定的npm命令,如`npm install user/repo`或`npm install git+ssh://git@github.com:user/repo.git`。如果需要SSH,可以使用`npm install git+ssh://git@github.com:user/repo.git#branch`。此外,npm还支持直接从Gist、Bitbucket、Gitlab等安装。确保已安装git,因为某些安装可能需要它。如果使用最新版npm仍出现问题,可能是所安装包本身的问题。
摘要由CSDN通过智能技术生成

本文翻译自:How to install an npm package from GitHub directly?

Trying to install modules from github results in: 尝试从github安装模块会导致:

ENOENT error on package.json. package.json出现ENOENT错误。

Easily reproduced using express: 使用express可以轻松复制:

npm install https://github.com/visionmedia/express throws error. npm install https://github.com/visionmedia/express引发错误。

npm install express works. npm install express工程。

Why can't I install from github? 为什么我不能从github安装?

Here is the console output: 这是控制台输出:

npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0

#1楼

参考:https://stackoom.com/question/1BT41/如何直接从GitHub安装npm软件包


#2楼

Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. 因为https://github.com/visionmedia/express是网页的URL,而不是npm模块。 Use this flavor: 使用以下味道:

git+https://git@github.com/visionmedia/express.git

or this flavor if you need SSH: 如果您需要SSH,也可以使用以下方法:

git+ssh://git@github.com/visionmedia/express.git

#3楼

You can also do npm install visionmedia/express to install from Github 您也可以执行npm install visionmedia/express从Github安装

or 要么

npm install visionmedia/express#branch

There is also support for installing directly from a Gist, Bitbucket, Gitlab, and a number of other specialized formats. 还支持直接从Gist,Bitbucket,Gitlab和许多其他特殊格式进行安装。 Look at the npm install documentation for them all. 查看所有这些文件npm install 文档


#4楼

如果未安装git,我们可以尝试

npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master

#5楼

The current top answer by Peter Lyons is not relevant with recent NPM versions. 彼得·里昂斯(Peter Lyons)当前的最高答案与最新的NPM版本无关。 For example, using the same command that was criticized in this answer is now fine. 例如,现在可以使用在此答案中批评的相同命令。

$ npm install https://github.com/visionmedia/express

If you have continued problems it might be a problem with whatever package you were using. 如果您仍然遇到问题,则可能是所使用的任何软件包都存在问题。


#6楼

还有npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}以使用其他分支。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值