How can I install an npm package from my bitbucket repository?

Robert Heath March 18, 2018

How can I install an npm package from my bitbucket repository?

6 answers

9 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 19, 2018

Hi Robert!

You can do that by typing 

npm install git+ssh://git@bitbucket.org/{user}/{repository}.git

I also found a blog that might be useful for you: npm install modules from Bitbucket private repositories.

Hope that helps!

Ana

yamilpadron
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 19, 2018

Is not working for me... 

Like David Tremblay-Fafard likes this
Srinivas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 31, 2019

If my ssh has a passphrase, npm is stuck without any prompt to enter passphrase or throwing an error. If I try to use https, npm throws  "To make a call, you need to use an app password." If I create an app password I cannot do it for each project and that makes all my projects visible with the password. Do you have any other alternatives in this scenario?

Srinivas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2019

I solved the above issue by using ssh with a passphrase. When npm install is stuck without any prompt, I just enter the passphrase for my ssh file and it works as expected. If entering your passphrase first time didn't work, try entering it multiple times (max 3 times).

Like Joseph Wylie likes this
Ian Walters
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 2, 2020

can also use ssh-agent to avoid passphrase during npm install

Segzpair
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2020

what other form of authentication apart from SSH is allowed to access the package?

2 votes
Catalin Mustata
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 29, 2020

The "proper" way to do this (if not using a private package repository) is to use https authentication instead of ssh. Create a deploy key for the repository you wish to use as a dependency and put that into your "package.json" like so

git+https://<deploy_token_user>:<deploy_user_password>@bitbucket.com/<user>/<repo>[#<version>]
2 votes
lobna arouini
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 17, 2019
  1. i Add "mymodule": "git+https://bitbucket.org/cname/mymodule.git" to dependencies within my project 
  2.  run npm install, they prompt a dialog to enter username and pass
  3. Voila! works

 

I suppose you may need to create ssh key and add it to your bitbucket settings in case your module is private 

1 vote
Adam Gerthel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 21, 2019

It works for me, but when running `npm install` or `npm update` any package that has been installed using the suggested way gets removed. It's annoying because it's really easy to miss since you have to scan package-lock.json for the change.

EDIT: For clarity, the repos that this is happening with are private (but I can initially install etc, so I do have access via git)

John Ericson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 18, 2019

Adam, try adding -S (for dependency) or -D (for devDependency).

npm install -S git+ssh://git@bitbucket.org/{user}/{repository}.git

That will save the dependency to your package.json so next time you install it should not get removed.

Adam Gerthel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 19, 2019

Right, but that's not what's happening. Like I said, the package gets removed from the lockfile when running `npm install` (and it would never have been in the lockfile if I hadn't used -S or -D). I've never seen this happen with any other package, so I'm guessing that it has to do with Bitbucket.

0 votes
Rob Lingstuyl
Contributor
June 13, 2024

Using node v20.13 I'm not getting this message any update as to standard recommendations?

git+ssh://git@bitbucket.org:<org>/epitel-node-utils.git and 

git+ssh://git@bitbucket.org/<org>/epitel-node-utils.git

both give the same error

0 votes
Atalie
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 27, 2023

Hi, has anyone encountered when adding ssh url in dependencies and then run npm install,  the terminal still prompts for username and password even though I already setup the ssh key. Git clone works but npm install seems to not recognize the ssh key. 


dependencies:{
test-module:git
+ssh://git@bitbucket.org/{user}/{repository}.git#v1.0.0
}
Rob Lingstuyl
Contributor
June 13, 2024

this is the full error message (node:26291) [DEP0170] DeprecationWarning: The URL git+ssh://git@bitbucket.org:<org>/epitel-node-utils.git is invalid. Future versions of Node.js will throw an error.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events