Integrating a Private GitHub Repository as an npm Dependency

I’m having trouble installing a private GitHub repository dependency via npm. What is the correct syntax for this integration?

I’ve encountered this issue in several projects and found that while using the GitHub URL directly in package.json works for many, configuring authentication through the .npmrc file can simplify matters when dealing with multiple private repositories. In my experience, it has been helpful to create a GitHub Personal Access Token with the required permissions, then add the appropriate authentication token line to my .npmrc file, which is usually located in the home directory. After this, referencing the private repo in package.json becomes much more streamlined. Just take care to keep the token secure and avoid committing it to version control.

I’ve dealt with this issue before. The key is to use the correct URL format in your package.json. For a private GitHub repo, you’ll want to use the SSH URL like this:

“dependencies”: {
“your-package-name”: “git+ssh://[email protected]:username/repo.git#branch-or-tag”
}

Replace ‘username/repo’ with the actual GitHub path, and optionally specify a branch or tag. Make sure you have SSH access to the repo. If you’re using HTTPS, you’ll need to include your GitHub Personal Access Token in the URL.

Remember to run ‘npm install’ after updating your package.json. This should pull in the private repo as a dependency.

hey mate, i’ve had this issue too. the easiest way is to use the github url in ur package.json like this:

“dependencies”: {
“your-pkg”: “github:username/repo”
}

make sure u have access to the repo and run npm install. should work like a charm!