Trying to install modules from GitHub results in this error:
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
"express": "github:visionmedia/express"
to the "dependencies"
section of package.json file
, then run: npm install
(as mentioned below)
Because https://github.com/visionmedia/express
is the URL of a web page and not an npm module. Use this flavor: git+{url}.git
git+https://github.com/visionmedia/express.git
or this flavor if you need SSH:
git+ssh://git@github.com/visionmedia/express.git
To install from GitHub, you can also do
npm install visionmedia/express
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. Look at the npm install
documentation for them all.
github.com
only.
If Git is not installed, we can try:
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
master
. Probably safer to do it that way.
/tarball/
at first
As of September 2016, installing from vanilla HTTPS GitHub URLs now works:
npm install https://github.com/fergiemcdowall/search-index.git
You can't 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 repository is in an npm-usable state, you can now quite happily install directly from GitHub.
In October 2019, we are now living through "peak TypeScript/React/Babel", and therefore JavaScript compilation has become quite common. If you need to take compilation into account, look into prepare
. That said, NPM modules do not need to be compiled, and it is wise to assume that compilation is not the default, especially for older node modules (and possibly also for very new, bleeding-edge "ESNext"-y ones).
dist
folder, and most don't. The issue I linked to is an npm bug - the prebuild
step is not run when installing from GitHub. As an example, try installing node-influx/node-influx.
dist
folders CAN be installed from GitHub, for example: npm install https://github.com/fergiemcdowall/search-index-adder
works perfectly.
/lib
(as if you had a dist folder). My point is that just including the GitHub URL of a repo in package.jons isn't guaranteed to work for installing that repo. Modules written in TypeScript, for example, need push their transpiled code into the repo. They typically don't do this, but rather use a prepublish script to dump the .JS code into a dist folder, which gets uploaded to npmjs.com.
prepare
script for bare "installs", which includes git deps. Which means the above comments around compilation and dist folders is out of date. Any package that properly sets their compilation to run on prepare
will work just fine as a git dep without committing any compiled assets into git.
The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.
npm install git+ssh://git@github.com:<githubname>/<githubrepo.git[#<commit-ish>]
npm install git+ssh://git@github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
npm install git+https://git@github.com/<githubname>/<githubrepo.git>
npm install git://github.com/<githubname>/<githubrepo.git>
npm install github:<githubname>/<githubrepo>[#<commit-ish>]
However, something notable that has changed recently is npm adding the prepare
script to replace the prepublish
script. This fixes a long-standing problem where modules installed via Git did not run the prepublish
script and thus did not complete the build steps that occur when a module is published to the npm registry. See Run prepublish for Git URL packages #3055.
Of course, the module authors will need to update their package.json file to use the new prepare
directive for this to start working.
.gitignore
files! stackoverflow.com/questions/48287776/…
git://
protocol is no longer supported (it was when this answer was written)
There's also npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}
to use a different branch.
prepare
script. I was just trying to install a branch of the whole repo in a test repo, but since the built code wasn't checked into GitHub, all that got installed was package.json
and the readme. This tarball
approach using the full URL installed all the source files, which is what I needed.
prepare
method! You just need to watch out for issues from also including a .gitignore
: stackoverflow.com/questions/48287776/…
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.
npm install https://github.com/visionmedia/express
If you have continued problems it might be a problem with whatever package you were using.
The general form of the syntax is
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
which means for your case it will be
npm install git+ssh://git@github.com/visionmedia/express.git
From npmjs docs:
npm install : Installs the package from the hosted git provider, cloning it with git. For a full git remote url, only that URL will be attempted.
You can do:
npm install git://github.com/foo/bar.git
Or in package.json
:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
This works for me and it is less typing.
npm i github:<UserName>/<RepoName>
package.json
{
"dependencies": {
"name": "github:<UserName>/<RepoName>"
}
}
Install it directly:
npm install visionmedia/express
Alternatively, you can add "express": "github:visionmedia/express"
to the "dependencies"
section of package.json
file, then run:
npm install
You could also do
npm i alex-cory/fasthacks
or
npm i github:alex-cory/fasthacks
Basically:
npm i user_or_org/repo_name
You can directly install a GitHub repository by the npm install
command, like this:
npm install https://github.com/futurechallenger/npm_git_install.git --save
NOTE: In the repository which will be installed by npm command:
maybe you have to have a dist folder in you repository, according to Dan Dascalescu's comment. You definitely have to have a package.json in your repository! Which I forget add.
dist
folder or any build code in your repo. You just need to use a prepare
script in package.json
.
Simple:
npm install *GithubUrl*.git --save
Example:
npm install https://github.com/visionmedia/express.git --save
I tried npm install git+https://github.com/visionmedia/express
but that took way too long and I wasn't sure that would work.
What did work for me was - yarn add git+https://github.com/visionmedia/express
.
Below piece of code worked for me to install from github repository:
npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>
You can get ssh clone link as below:
https://i.stack.imgur.com/EZ2fU.png
So for above screenshot repository, you may need to import as below,
npm install git+ssh://git@github.com:Siddhu2/calculator-chatbot.git#master
where master is my branch and it is optional since I have only one branch.
Sometimes I need to install from a specific branch or commit. To make things simple I just use https://gitpkg.vercel.app/
https://i.stack.imgur.com/Gpuak.png
If you get something like this:
npm ERR! enoent undefined ls-remote -h -t https://github.com/some_repo/repo.git
Make sure you update to the latest npm and that you have permissions as well.
The only command that worked for me was npm i MY_PACKAGE_NAME:MY_REPOSITORY#BRANCH_NAME
No need to do much; this helped me:
Yarn add <git_name>:<github_name>/<Repository_name>.git
Example:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git
And if you want to add some specific commit or branch name then add #
.
Example:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git#master
Example:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git#c978U57
Try this command:
npm install github:[Organisation]/[Repository]#[master/BranchName] -g
This command worked for me:
npm install github:BlessCSS/bless#3.x -g
Success story sharing
git+https://github.com/visionmedia/express.git
to use https rather than ssh.package.json
file or else you will get this error:Error: ENOENT, open 'tmp.tgz-unpack/package.json'
.#
to use a specific branch from the shell, i.e.:npm install git+https://github.com/user/repo.git\#branch