39

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

npm install git@bitbucket.org: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.

hong4rc
  • 3,999
  • 4
  • 21
  • 40
Eugene Kostrikov
  • 6,799
  • 6
  • 23
  • 25

7 Answers7

73
npm install git+ssh://git@bitbucket.org/{user}/{repository}.git
user1610694
  • 1,078
  • 7
  • 9
  • 1
    but it saves a temporary path to the package.json. is that normal? – majidarif Feb 09 '15 at 22:22
  • 2
    this other answer may be relevant (or not) http://stackoverflow.com/a/10391718/2586761 – ptim Feb 19 '15 at 04:56
  • 3
    .. and it helped my sanity to check that my credentials were functioning: `ssh -T git@github.com` – ptim Feb 19 '15 at 05:00
  • 2
    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 – amann Aug 22 '16 at 15:12
  • 1
    What about tag version? – basarat Dec 22 '16 at 22:53
  • @basarat for tag version just append it as #1.0.0 ( e.g. .../{repository}.git#1.0.0 ) – Diego ZoracKy Jan 04 '17 at 18:12
  • With this you can also get weird errors from `npm`, if you have the same package previously installed from local path or the same package under a different name. Check your `node_modules` in the repository where you want to install a package from git in and delete other versions of the package, even if they are named differently. Fixed it for me. – Zelphir Kaltstahl May 03 '18 at 07:44
  • amazing. you rock !! – Rahul Gaba Dec 03 '18 at 10:24
  • Not sure why, but my packages that are installed this way keeps getting removed from node_modules (and package-lock.json) when running `npm install` or `npm update`. So after install/update I always have to run npm install specifically for those packages. I have no idea why, and it's really error-prone because it's easy to forget. – Adam Gerthel Jan 21 '19 at 09:53
  • i am linking to bitbucket, I still need to enter my password anyway to avoid it ? – Cpp crusaders May 13 '22 at 17:42
19
npm install bitbucket:<bitbucketname>/<bitbucketrepo>
gztomas
  • 3,030
  • 3
  • 27
  • 38
7

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
Abraham
  • 8,525
  • 5
  • 47
  • 53
  • 3
    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. – Eric Uldall Nov 13 '19 at 19:09
3
npm install ssh://git@bitbucket.org:{user}/{repository}.git
smacktrack
  • 31
  • 1
3

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
sver
  • 866
  • 1
  • 19
  • 44
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:password@gitserver.com/git/my-module.git#branchName",
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.
abmap
  • 141
  • 5