1. 程式人生 > >當執行npm publish 時,出現unauthorized 和 is not in the npm registry

當執行npm publish 時,出現unauthorized 和 is not in the npm registry

當執行npm publish,發生瞭如下錯誤:

appledeMacBook-Pro:nini-react apple$ npm publish
npm ERR! publish Failed PUT 401
npm ERR! code E401
npm ERR! 404 unauthorized Login first: nini-react
npm ERR! 404
npm ERR! 404  'nini-react' 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/apple/.npm/_logs/2018-02-04T00_32_35_475Z-debug.log
appledeMacBook-Pro:nini-react apple$ 

起先以為是賬戶的問題,我就執行了npm adduser 和 npm login 都不行。

您首先執行下 npm adduser ,輸入您相應的 Username  Password  Email: (this IS public) ,關鍵的一步來了!

Logged in as 您的Username on https://registry.npmjs.org/.

如果 on 後面不是 https://registry.npmjs.org/ ,而是其他的映象,比如我們大家常見的淘寶映象:

http://registry.npm.taobao.org/

那麼您首先替換成原來的,替換成原來執行如下命令:

npm config set registry https://registry.npmjs.org/

最後,替換完畢再執行 npm adduser  npm publish ,這樣應該就ok了!

看下是不是你配置了源,比如為了加速使用了淘寶的映象

如果使用了淘寶映象,先還原淘寶映象

1.使用 cnpm 的注意報錯:

no_perms Private mode enable, only admin can publish this module

  設定回原本的就可以了:

npm config set registry http://registry.npmjs.org 

2.npm包package.json中registory屬性一定要填寫,每次publish npm時package.json中version版本一定要大於上一次。

3.npm publish failed put 500  unexpected status code 401這樣的報錯資訊,往往是沒有登入成功,操作npm login

在使用npm的時候,免不了要註冊一個使用者

註冊使用者有兩種方式: 第一種是進入官網介面進行註冊:點選進入官網

                                     第二種是:使用 npm adduser 的方式;

                                                    

                但是使用第二種方式可能註冊不一定成功,那麼在後續上傳個人的模組的時候就會出現如下錯誤:

也就是說,你需要重新註冊才可以;