How to install an npm package from GitHub directly

2019-01-01 04:14发布

Trying to install modules from github results in:

ENOENT error on package.json.

Easily reproduced using express:

npm install https://github.com/visionmedia/express throws error.

npm install express works.

Why can't I install from 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

13条回答
梦该遗忘
2楼-- · 2019-01-01 04:43

There's also npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH} to use a different branch.

查看更多
浪荡孟婆
3楼-- · 2019-01-01 04:47

You could also do

npm i alex-cory/fasthacks

or

npm i github:alex-cory/fasthacks

Basically:

npm i user_or_org/repo_name
查看更多
余欢
4楼-- · 2019-01-01 04:50

Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. Use this flavor:

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

or this flavor if you need SSH:

git+ssh://git@github.com/visionmedia/express.git
查看更多
浅入江南
5楼-- · 2019-01-01 04:53

UPDATE now you can do: npm install git://github.com/foo/bar.git
or in package.json:

"dependencies": {
  "bar": "git://github.com/foo/bar.git"
}
查看更多
低头抚发
6楼-- · 2019-01-01 04:55

If git is not installed, we can try

npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
查看更多
骚的不知所云
7楼-- · 2019-01-01 04:56

You can directly install an github repo by npm install command, like this: npm install https://github.com/futurechallenger/npm_git_install.git --save

NOTE: In the repo which will be installed by npm command:

  1. maybe you have to have a dist folder in you repo, according to @Dan Dascalescu's comment.
  2. You definitely have to have a package.json in you repo! which I forget add.
查看更多
登录 后发表回答