We want to use the private repository function from Gitlab. For that we created a group and in that group we want to create several projects. I'm able to build versions and packages and publish them using semantic-version. I can see that the packages are visible at the 'Package Registry' page.
But I have trouble installing those packages in other projects using npm install
. I only gets a 404 error when I run the install command. I tried several things which I can find in the gitlab docs.
This is how the structure in my account looks like:
The packages are called @company/license en @company/auth, according to the gitlab guidelines.
I want to be able to install all the packages and the future ones, so using the 'instance-level' should be the solution here (altough 'project level' isn't working either).
So, I added
@company:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=(personal access token)
to my .npmrc
. We are not using our own instance at gitlab.
But when try to run npm install @company/license
I get Not Found - GET https://gitlab.com/api/v4/packages/@company%2flicense
. That is the same error which I get when I sent a GET request to that endpoint in Postman with my token as Bearer Auth.
This error also occurs when I set the project level url (https://gitlab.com/api/v4/projects/(project id)/packages/npm
) in my .npmrc
file.
I have tried to using a group url (https://gitlab.com/api/v4/groups/(group id)/packages/
) which gives me the packages (in my browser and in postman) but when setting this URL as registry I get the same error.
NPM adds the package name in the URL and that gives indeed a 404.
What I'm doing wrong? I've seen a lot of people have this work, so it must be a stupid thing which I can't see.
I found out that my scope was not correct. I was thinking that the scope was based on the folder where the projects where located,but the scope needs to be the same as your username. So in my case the scope needs to be @root/license. Where root is of course something like 'company name inc.', so scope will be @company-name-inc. It's the same name which you can see in the URL as first 'page' when you are opening a project or group: https://gitlab.com/company-name-inc/group-name/project-name
In my .npmrc
file I can now just add the instance based entrypoint and that will work!
@company-name-inc:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=[deploy token]