Reputation: 30997
I want to globally setup an NPM registry for a specific scope to be used with a specific token.
I know that I can use :
$ npm login --scope=@organisation
And I can also write a ~/.npmrc
with :
//registry.npmjs.org/:_authToken=XXXX
But what I want is a combinaison of the two methods: Using the token at when assigning the registry URL to my scope.
I tried :
npm config set @organisation:registry https://registry.npmjs.org/:_authToken=XXXX
But when running an NPM command (eg npm install @organisation/my-package
). I get the following error :
npm ERR! Darwin 15.6.0
npm ERR! argv "/Users/me/.nvm/versions/node/v6.2.2/bin/node" "/Users/me/.nvm/versions/node/v6.2.2/bin/npm" "install" "@organisation/my-package"
npm ERR! node v6.2.2
npm ERR! npm v3.10.3
npm ERR! code E403
npm ERR! you do not have permission to publish ":_authToken=XXXX". Are you logged in as the correct user? : :_authToken=XXXX
Is there a solution? (I need to use a token and no env variable).
PS: https://github.com/npm/npm/issues/7995#issuecomment-175915766 but it's not working...
Upvotes: 41
Views: 71151
Reputation: 825
Looks like the npm syntax has changed. The answer above does not work anymore with NPM 10.2.4! Now an equal sign seems to be required, like this:
npm config set @myco:registry=https://reg.example.com
Upvotes: 2
Reputation: 1311
According to the official documentation you should be able to associate a scope with a registry when logging in. Is this what you want?
Did you try the following?
npm login --registry=https://reg.example.com --scope=@myco
If you dont want to login, but rather want to specify the token explicitly, the following should work:
npm config set @myco:registry https://reg.example.com
npm config set //reg.example.com/:_authToken xxxxxxxx
Note that the registry url must be normalized for this to work, ie it shouldn't include scheme and must end with a slash.
Upvotes: 92