npm publish 报错 403
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、确保包名没有被使用
更多推荐
已为社区贡献1条内容
所有评论(0)