npm publish 报错 403

1 背景

最近想把自己写的组件,发布到npm仓库,慢慢积累,最后形成一个有体系的东东。
在实践过程中,执行 npm publish 的时候,发生了如下错误,控制台提示如下:

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/xxx-xxx-npm - Forbidden
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

在排查过程中,发现 error code 为403也可能有多种原因。所以在此总结一下

npm 的版本 为 6.14.6

2 问题排查方向

如果执行 npm publish ,控制台 errcode 为 403 ,可能的问题如下:

2.1 npm 账号问题

1、 执行 npm whoami , 验证账号是否正确
2、 执行 npm login , 重新登录
3、 账号邮箱未验证

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/xxx-xxx-npm - Forbidden
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

2.2 package.json文件 name 字段 重名

例如我们把name改为 loadsh(一个已经存在的包),控制台提示如下。

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/loadsh - You do not have permission to publish "loadsh". Are you logged in as the correct user?
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

2.3 package.json文件 version 字段不对

假设我们在一个已发布的包中,且包未修改的情况下,重复执行npm publish
error code 403 提示如下

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/test-xsl-npm - You cannot publish over the previously published versions: 1.0.0.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

2.4 仓库地址问题

3 总结

1、 确定
2、确保包名没有被使用
在这里插入图片描述

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值