本文翻译自: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}
以使用其他分支。