Search code examples
npmgitlab.npmrc

Unable to set correct npm config for group registry


I have two npm packages that are private repositories hosted on gitlab.com under a group organization. My first package lives well and get updated and downloaded by users of the same organisation.

To install a private scoped package, the doc says:

# Set URL for your scoped packages.
# For example package with name `@foo/bar` will use this URL for download
npm config set @foo:registry https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/

So my .npmrc looked like

@mygroup:registry=https://gitlab.com/api/v4/projects/<id-project-1>/packages/npm/
//gitlab.com/api/v4/projects/<id-project-1>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/projects/<id-project-2>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/packages/npm/:_authToken=<token>

Obviously, everything works fine for the first package but not for the second one.

What I can't understand is why a scoped package should refer to a unique project url?

Because of this, I can't install both of my packages: the url of my scoped packages will only be valid for one of them.

I looked at the api endpoint to return a list of my group's packages I found this: https://docs.gitlab.com/ee/api/packages.html#within-a-group

So I updated my .npmrc to

@mygroup:registry=https://gitlab.com/api/v4/groups/mygroup/packages/npm/
//gitlab.com/api/v4/projects/<id-project-1>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/projects/<id-project-2>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/packages/npm/:_authToken=<token>

But it doesn't work. On the group/group-id/packages route I only get gitlab infos but nothing in an npm friendly format.

How to install more than one private scoped npm package hosted under the same group?


Solution

  • The instance level endpoint seems answer to your situation instance-level-npm-endpoint

    Using:

    npm config set @mygroup:registry https://gitlab.example.com/api/v4/packages/npm/
    npm config set -- '//gitlab.example.com/api/v4/packages/npm/:_authToken' "<your_token>"
    

    You should be able to publish @mygroup/project1 & @mygroup/project2