2

I would like to install repos to a parent repo and specify by branch name. I have tried the following:

npm install username/repo#branchName --save
npm install username/repo@branchName --save
npm install username/repo#tag --save
npm install username/repo@tag --save

I'm getting an error that says:

Could not install from {theRepoWithBranch} as it does not contain a package.json file.

The repo definitely contains a package.json file. I'm wondering if this is a permissions issue given I'm using an enterprise npm registry.

zero_cool
  • 3,960
  • 5
  • 39
  • 54

1 Answers1

1

npm/npm issue 19788 does mention:

Currently, npm does not support installation of modules from git services hosted on private domain names.
That includes both Github for Enterprise on custom domains as well as instances of gitlab, gitea, gogs, bitbucket and many others, basically anything hosted on a custom domain name.

With the comment:

So, obviously you reference installing via an http(s):// URL directly, but just as an fyi, our GitLab Enterprise instance allows us to install using a slightly different format.
We have 2FA enabled, so it requires SSH to be used.
From the docs.

npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>

We were able to actually install our repos like this:

npm install git+ssh://git@gitlab.mydomain.com:user/repo.git

So this is more a URL format combined with permission issue.
Regarding the branch, as seen here, your syntax is correct.

And:

if I prepend git+ on the HTTPS URL it works (I run gitea which accepts basic auth)

See also npm/hosted-git-info PR 30

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hmmm...for some reason when it is installed there is no lib or dist directories. The node_modules are also included. For any other install the node_modules are not included and there are lib and dist directories...Do you know how to get around this? – zero_cool Sep 15 '19 at 19:14
  • @zero_cool Not on the top of my head. It would be interesting to explore that particular case in a separate question, highlighting the differences between that incomplete module, and others which do install properly. – VonC Sep 15 '19 at 19:33
  • I figured it out :) You add a "prepare" script to your package.json that handles the build. It looks like prepare gets run on npm i if it exists. We use builder for builds so the script that worked for me was what works locally. I imagine that whatever works for you locally would work in that script. – zero_cool Sep 15 '19 at 20:05