Reputation: 10089
I am trying to use my first private npm package on a gitlab private instance
I added @ajouve:registry=https://gitlab.my-website.io/api/v4/packages/npm/
to .npmrc
the command npm get
seems to return the correct config
; "project" config from /Volumes/Work/service/.npmrc
@ajouve:registry = "https://gitlab.my-website.io/api/v4/packages/npm/"
; "cli" config from command line options
omit = []
user-agent = "npm/7.5.4 node/v12.18.1 darwin x64"
; node bin location = /usr/local/bin/node
; cwd = /Volumes/Work/service
; HOME = /Users/ajouve
; Run `npm config ls -l` to show all defaults.
But when I want to add the package
npm install --save @ajouve/my-module
I have
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@ajouve/my-module Not found
npm ERR! 404
npm ERR! 404 '@ajouve/my-module@*' 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:
npm ERR! /Users/ajouve/.npm/_logs/2021-03-19T15_06_50_186Z-debug.log
It goes to https://registry.npmjs.org
Running npm config ls -l | grep registry
I have
metrics-registry = "https://registry.npmjs.org/"
registry = "https://registry.npmjs.org/"
@ajouve:registry = "https://gitlab.my-website.io/api/v4/packages/npm/"
Upvotes: 6
Views: 3653
Reputation: 2368
You could try this:
npm config set registry http://registry.npmjs.org
Or sometimes you just need to adduser and login to fix this problem with a private package. Have a look at this doc: npm-addUser
Commands should be something like this:
npm adduser
npm login
Upvotes: 0
Reputation: 55
As someone who started using Gitlab's registry a couple days ago, i ran on the same issue. On the .npmrc, the scope name has to meet with your packet scope. For example, if we have the project A, it's package.json should be like this:
{
"name": "@myscope/myproject",
...Rest of your package.json
And on your project B, the .npmrc must match the scope
@myscope:registry=https://gitlab.com/api/v4/packages/npm/
Then after, make sure you authenticate with the scoped registry, otherwise NPM will throw a error or ignore and go search on NPM Registry
$ npm config set @myscope:registry https://gitlab.com/api/v4/packages/npm/
$ npm config set -- '//gitlab.com/api/v4/packages/npm/:_authToken' "<your_token>"
NOTE: <your_token> should be a access token created on your Gitlab Profile. You can create this by going on Preferences > Access Tokens. Make sure to check "read_registry" before creating the token.
Then, you can install your package easily
$ npm install --save @myscope/myproject
EDIT: If you are using a self-hosted gitlab instance, it follows the same, just remember to change "gitlab.com" to your gitlab instance url.
Upvotes: 2
Reputation: 957
Instead of git://, use git+ssh://
npm i -S git+ssh://[email protected]:<org>/<project>.git
Here you can get several answers
Install npm module from gitlab private repository
Upvotes: 1
Reputation: 5699
for the first installation you need to run
npm config set @ajouve:registry=https://gitlab.my-website.io/api/v4/packages/npm/
Upvotes: 0
Reputation: 177
Try this, it should work.
npm install --save @ajouve/my-module --registry=https://gitlab.my-website.io/api/v4/packages/npm/
Another way is to create group endpoint in the private instance which will point hosted + proxy to public packages and update your registry to point to that endpoint so both private and public packages will work.
Upvotes: 0