Error publishing to package registry

Describe your question in as much detail as possible:

I’m trying to store all of my packages in a single GitLab project (using the most recent version of self hosted install of GitLab) Store all of your packages in one GitLab project | GitLab

I’ve setup a new project and verified that the package registry is enabled.

I configured .npmrc from a different repo, that has my package source code. In this file, I’ve specified the project number (6) to define the main registry project. It’s a private project, so I created a deploy key with read/write permissions to the main registry project, and defined that key as an env in the repo I’m building from. (Package scope + domain are obfuscated for privacy)

Set URL for your scoped packages.


Add the token for the scoped packages URL.


Add token for uploading to the registry.


I also edited my package.json file:
“publishConfig”: {
@my-org:registry”: “https://{my-domain}/api/v4/projects/6/packages/npm/”

And I created gitlab-ci.yml:

This file is a template, and might need editing before it works on your project.

image: node:14.15.4

Validate that the repository contains a package.json and extract a few values from it.

- |
if [[ ! -f package.json ]]; then
echo “No package.json found! A package.json file is required to publish a package to GitLab’s NPM registry.”
echo ‘For more information, see NPM packages in the Package Registry | GitLab
exit 1
- NPM_PACKAGE_NAME=(node -p "require('./package.json').name") - NPM_PACKAGE_VERSION=(node -p “require(’./package.json’).version”)

Validate that the package name is properly scoped to the project’s root namespace.

For more information, see NPM packages in the Package Registry | GitLab

stage: build
- |
if [[ ! $NPM_PACKAGE_NAME =~ ^@CI_PROJECT_ROOT_NAMESPACE/ ]]; then echo "Invalid package scope! Packages must be scoped in the root namespace of the project, e.g. \"@{CI_PROJECT_ROOT_NAMESPACE}/${CI_PROJECT_NAME}""
echo ‘For more information, see NPM packages in the Package Registry | GitLab
exit 1

Publish the package. If the version in package.json has not yet been published, it will be

published to GitLab’s NPM registry. If the version already exists, the publish command

will fail and the existing package will not be updated.

stage: deploy
- npm publish

  • What are you seeing, and how does it differ from what you expect to see?

When I run CI from a different repo to build + publish the package, it fails with:
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://{my-domain}/api/v4/projects/6/packages/npm/@my-org%2fmy-repo
npm ERR! 404
npm ERR! 404 ‘@my-org/my-repo@1.0.0’ 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.

It should publish the package, so when I browse to the main project, the package will be there.

  • What version are you on (Hint: /help) ? and are you using self-managed or
    GitLab self-managed 13.7.1-ee (d49cd5e5165)

  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

I’ve also tried using CI_JOB_TOKEN for auth in my .npmrc file, instead of a deploy token. The error is the same either way.

@encausticcello Greetings! I have reviewed your steps shown above and everything looks correct. The only thing that I think may be the issue is to ensure that the {my-domain} is the gitlab fqdn and not the registry address fqdn.

Ah ok. I have a custom domain set for the registry - should that only be used for the Docker repo?

I just tested this using the gitlab fqdn instead of the registry address, and it’s working as expected now. Thank you for the assist!