npm - publish

npm - publish

来源 npm publish —— 发布npm包

steps

  • 在npm官网注册账户
  • 在填写的邮箱中验证邮箱
  • 在命令行中登录
  • 使用npm源
  • 进入需要发布的目录发布项目
  • 修改更新版本

注册

进入进行注册,如果已经注册进入跳到第三步

error

npm发布及解决403 403 Forbidden - PUT http://10.9.251.7:7001问题
npm publish 时提示需要升级TLS 1.2的解决方案
npm常用命令
npm config set registry https://registry.npmjs.org/
发布npm包时遇到的一些坑

# 邮箱未验证
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! you must verify your email before publishing a new package: https://www.npmjs.com/email-edit : your-package

# 没有权限发布
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! You do not have permission to publish "your-package". Are you logged in as the correct user? : your-package
## 你的包和别人的包重名了,npm 里的包不允许重名,所以去 npm 搜一下,改个没人用的名字就可以了。

# 需要登录
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
## 后面已经注明了,输入npm adduser重新登录就可以了,过程和npm login一样,这个问题在你切换了 npm 源之后或登录过期后都有可能发生。

# 只有管理员才有权限发布
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! [no_perms] Private mode enable, only admin can publish this module [no_perms] Private mode enable, only admin can publish this module: your-package
## 这个是你的源设置成第三方源的时候才有可能发生,比如设置了淘宝源就可能会导致该问题。只要把源改回默认的就可以了,如下:
npm config set registry http://registry.npmjs.org

# 包名过于类似
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! Package name too similar to existing packages; try renaming your package to '@hopgoldy/auto-git' and publishing with 'npm publish --access=public' instead : your-package
## 如果npm上已经有了不少和你的包名类似的包,就会出现这个问题,在package.json中修改你的包名就可以了

# 无法发布到私有包
npm ERR! publish Failed PUT 402
npm ERR! code E402
npm ERR! You must sign up for private packages :
## 这个当你的包名为@your-name/your-package时才会出现,原因是当包名以@your-name开头时,npm publish会默认发布为私有包,但是 npm 的私有包需要付费,所以需要添加如下参数进行发布:
npm publish --access public
posted @ 2022-01-17 10:35  zc-lee  阅读(393)  评论(0编辑  收藏  举报