Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globally configure NPM with a token registry to a specific scope (@organisation)

Tags:

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...

like image 768
Yves M. Avatar asked Aug 04 '16 10:08

Yves M.


1 Answers

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.

like image 116
deadbeef Avatar answered Sep 27 '22 21:09

deadbeef