1

I have created a private npm registry using gitlab

I have the following .npmrc file, which is the same .npmrc file that I used to publish with no issues. I've replaced all company values with placeholders.

@myorg:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=[[MY_TOKEN_HERE]]
//gitlab.com/api/v4/projects/12345678/packages/npm/:_authToken=[[MY_TOKEN_HERE]]

When I go to install I get the following error message

npm install @myorg/my-package-name-here
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@myorg/my-package-name-here - Not found
npm ERR! 404
npm ERR! 404  '@myorg/my-package-name-here@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:

This to me looks like it's not picking up the .npmrc file as the registry is different.

I have checked and the file is definately .npmrc and not a different extension etc.

Anyone have any ideas?

EDIT

I've done some investigation and it does look like my .npmrc file is being used, however the registry

'https://gitlab.com/api/v4/packages/npm/@myorg/my-package-name-here'

is being redirected to

'https://registry.npmjs.org/@myorg/my-package-name-here'

which is why it will be showing up as this...

It does not explain to me why it can't be found though using the auth token etc that I used to publish?

user3284707
  • 3,033
  • 3
  • 35
  • 69

3 Answers3

5

I've figured it out...

Everything is fine other than @myorg does not match my gitlab org name.

e.g. the gitlab url is something like this:

https://gitlab.com/my-company/...

instead it needs to match the github url, so in the above example

@my-company

After switching this it all kicked into life and I am able to get the npm package.

user3284707
  • 3,033
  • 3
  • 35
  • 69
  • 1
    Oh man, thanks for figuring this one out & posting the solution here!! I had EXACTLY the same issue & couldn't find out why! Turned out that my registry scope was set to `@company-name` but the repo root directory is `the-company-name`, and matching those names totally solved the problem!! – Shan Oct 07 '21 at 23:52
  • 1
    Yeah I spent hours and hours with this not working, glad that I was able to help you solve your issue. – user3284707 Oct 08 '21 at 09:20
1

It is not necessarily true (as stated in the accepted answer) that the scope name "needs to match the github [sic] url" (believe github is meant to be GitLab).

Using GitLab, it is possible to have a scope name that does not match the root of your GitLab URL.

The difference is how the registry is configured in the project's (or user's) .npmrc.

From GitLab:

When you use the instance-level endpoint, only the packages with names in the format of @scope/package-name are available. For example, if your project is https://gitlab.example.com/my-org/engineering-group/team-amazing/analytics, the root namespace is my-org. When you publish a package, it must have my-org as the scope.

The registry config for an instance-level endpoint looks like this:

@scope:registry=https://gitlab.com/api/v4/packages/npm/

...however, if your scope name does not match the root of GitLab URL, you will need a project-level endpoint configuration:

@scope:registry=https://gitlab.com/api/v4/projects/<your_project_id>/packages/npm/.

https://docs.gitlab.com/ee/user/packages/npm_registry/index.html

Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55
1

My cents to help someone.

When you create a repository to handle with Package Registry, then you've created in a group or in your own user. It's very important to observe where you created it. Probably your registry repository url is something like this:

https://your.gitlab.com/{name_of_group_or_name_of_user}/[{optional_subgroup}/]{repository_registry_name}

Now, let's say you've a package in the url:

https://your.gitlab.com/my-group/my-package

And the url registry is:

https://your.gitlab.com/main/registry

The @scope of your my-package needs being @main/my-package, and not @my-group/my-package. If you define wrong @scope here, it gives you 404.

my-package:

{
    "name": "@main/my-package",
     ...
}

The @scope is the first segment of the url of your registry repository path.

v1d3rm3
  • 454
  • 5
  • 12