39

I'm trying to install a private package recently moved from github to bitbucket.

npm install [email protected]:owner/repo.git

ends up with

npm http GET https://registry.npmjs.org/git

(note package in the url) with this error:

npm ERR! notarget No compatible version found: git@'bitbucket.org:flyvictor/fortune-secruity.git'

(note a ' just after @)

I tried to escape @, wrap repo name in quotes, but always get same result.

For github we use urls formatted as git://github.com/owner/repo#v.v.v and this works fine! But if I use same syntax for bitbucket npm just hangs doing nothing.

Any idea?

p.s. keys, access right and so one are correct. I can contribute to these repos, clone them with git, but not to npm install. Github packages that get installed well are also private.

7 Answers 7

73
npm install git+ssh://[email protected]/{user}/{repository}.git
Sign up to request clarification or add additional context in comments.

11 Comments

but it saves a temporary path to the package.json. is that normal?
this other answer may be relevant (or not) stackoverflow.com/a/10391718/2586761
.. and it helped my sanity to check that my credentials were functioning: ssh -T [email protected]
How would you do it if the package is within a subdirectory of the repo? npm can't install a directory that doesn't contain a package.json
What about tag version?
|
20
npm install bitbucket:<bitbucketname>/<bitbucketrepo>

Comments

8

Declaimer: As Eric Uldall said: this method is easy but it lacks security. You have now committed a password in plain text to your repository. That's how is working out lately for me, but not recommended.


Straight from the npm Documentation for the install command:

$ npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]

Example:

$ npm install bitbucket:mybitbucketuser/myproject

The Yarn documentation for add as of today Feb 28, 2019 doesn't have support for git repositories.

The above example didn't work for me with private repositories, because you will need to generate a token to use it. How is that?

Login to your Bitbucket account and under user settings add an app password:

img

Then you can add the dependency to your package.json as:

"dependencies": {
    "module": "git+https://<username>:<app-password>@bitbucket.org/<owner>/<repo>.git"
}

or on your terminal type:

npm install git+https://<username>:<app-password>@bitbucket.org/<repo-owner>/<repo>.git

Don't forget to replace:

  • username: with your username
  • password: with your app password
  • repo-owner: with the owner of the repo
  • repo: with the repository name of the module

1 Comment

This method is easy but it lacks security. You have now committed a password in plain text to your repository. If you were to have a public repo that installed a private repo at build time, that private repo will now be accessible to anyone, thus making it not so private anymore. It's best to add either an account level ssh key from your machine or install custom deploy keys for each application/repo that is needed. Not to mention the user's question was not in regards to access but rather a syntax question about how to npm install from bitbucket.
4
npm install ssh://[email protected]:{user}/{repository}.git

1 Comment

Best answer for a repo behind SSH key auth in 2025
4

I tried a lot of ways but only this worked for me :

npm install -s https://bitbucket.org/owner/repo-name/commits/tag/0.1.0

Comments

1

if your git server is exposed on HTTP protocol and you want to install specific branch use following format

"your-module": "git+http://team-user:[email protected]/git/my-module.git#branchName",

Comments

0

So in order to install npm package from remote git repository, you need to make sure

  • You have git binary installed in your machine/virtual machine/container you're working on
  • You have access to the repo, and I recommend you to use https instead of ssh for the protocol for the public repo because ssh protocol requires you to have ssh credentials.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.