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
You can also do
npm install visionmedia/express
to install from Githubor
There is also support for installing directly from a Gist, Bitbucket, Gitlab, and a number of other specialized formats. Look at the
npm install
documentation for them all.Install it directly:
Alternatively, you can add
"express": "github:visionmedia/express"
to the"dependencies"
section ofpackage.json
file, then run:UPDATE sept 2016
Installing from vanilla https github URLs now seems to work:
EDIT: there are a couple of users commenting that you cant do this for all modules because you are reading from a source control system, which may well contain invalid/uncompiled/buggy code. So to be clear (although it should go without saying): given that the code in the repo is in an npm-usable state, you can now quite happily install directly from github
The current top answer by Peter Lyons is not relevant with recent NPM versions. For example, using the same command that was criticized in this answer is now fine.
If you have continued problems it might be a problem with whatever package you were using.
Try this command
this command worked for me.
The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.
However, something notable that has changed recently is npm adding the
prepare
script to replace theprepublish
script. This fixes a longstanding problem where modules installed via git did not run theprepublish
script and thus did not complete the build steps that occur when a module is published to the npm registry. See https://github.com/npm/npm/issues/3055.Of course, the module authors will need to update their package.json to use the new
prepare
directive for this to start working.