最近需要在npm上发布一个包,记录如下:
首先在 NPM 官网注册一个账号 或者输入命令
npm adduser
注册时会要求输入用户名,密码和邮箱。切记需要在邮件中确认。否则会造成npm publish 时出现
npm ERR! you must verify your email before publishing a new package
在npm adduser 或者 npm login 的时候,请注意看一下输入中
Logged in as <Your username> on https://registry.npmjs.org/.
是否是登录在 https://registry.npmjs.org/ 而不是其他镜像。比如淘宝镜像
Logged in as <Your username> on http://registry.npm.taobao.org/.
这样的话在发布时会提示 unauthorized
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
接下来输入命令
npm publish
即可发布成功