2016-08-04 26 views
7

我想全局設置特定scope的NPM註冊表,以便與特定的token一起使用。全局配置帶有令牌註冊表的NPM到特定範圍(@organisation)

我知道,我可以使用:

$ npm login [email protected] 

而且我也可以寫一個~/.npmrc有:

//registry.npmjs.org/:_authToken=XXXX 

但我想要的是兩種方法的combinaison:使用的令牌將註冊表URL分配給我的範圍時。

我想:

npm config set @organisation:registry https://registry.npmjs.org/:_authToken=XXXX 

但運行NPM命令時(如npm install @organisation/my-package)。我收到以下錯誤:

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 

是否有解決方案? (我需要使用一個令牌並且沒有env變量)。

PS:https://github.com/npm/npm/issues/7995#issuecomment-175915766但它不工作...

回答

6

根據你應該能夠associate a scope with a registry when logging in官方文檔。這是你想要的嗎?

您是否嘗試過以下方法?

npm login --registry=https://reg.example.com [email protected] 

如果你不想登錄,而是想明確指定令牌,下面應該工作:

npm config set @myco:registry https://reg.example.com 
npm config set '//reg.example.com/:_authToken' 'xxxxxxxx' 

注意註冊表URL必須歸這個工作,即它不應該包括方案,並且必須以斜線結尾。