I have a (test) npm package named @myScope/test
which I want to publish into a private gitlab registry within a gitlab project whose address is
https://gitlab.<something>/myId/test-npm-registry/
with ID 9630
First, I'm a bit confused with npm login
and .npmrc
. If I understand correctly, answers given to npm login
end-up as a couple of lines into .npmrc
, is that right?
So essentially, to instruct npm about authenticating to a registry, one can either:
- manually edit
.npmrc
- use
npm config set
- use
npm login
Based on what I read on the gitlab help, I've inserted the following lines into my .npmrc
:
@myScope:registry=https://gitlab.<something>/api/v4/projects/9630/packages/npm/
'//gitlab.<something>/api/v4/projects/9630/packages/npm/:_authToken'="${GITLAB_AUTH_TOKEN}"
Note: I had to use the project ID, having issues with the url format.
I have also added the following bit into the package.json :
publishConfig":{
"@myScope:registry": "https://gitlab.<something>/api/v4/projects/9630/packages/npm/"
}
Finally, I've created a token in gitlab, with "api, read_api, read_registry, write_registry"
rights and I have assigned the token to the GITLAB_AUTH_TOKEN
variable:
GITLAB_AUTH_TOKEN="xk4L7xxvzHuykyKawxQZ"
When I do npm publish
I'm getting the following message :
npm ERR! code E401
npm ERR! 401 Unauthorized - PUT https://gitlab.<something>/api/v4/projects/9630/packages/npm/@myScope%2ftest-npm-registry
npm ERR! A complete log of this run can be found in:
The logs doesn't help, nor does the verbose mode. Also, I'm not getting if I have to perform an explicit npm login
or if the configuration in the .npmrc
(with the token) should do the trick. I actually cannot do npm login
because the username has an @
character in it and npm refuses it.
Any ideas ?