npm publish 发布一个 Angular 库的时候报错以及解决方法

举报
Jerry Wang 发表于 2022/08/27 22:47:50 2022/08/27
【摘要】 我今天照着 npm 文件,打算把自己开发的 npm 库发布到公网上:npm login 之后,使用命名行 npm config set registry=http://registry.npmjs.org, 遇到如下错误:npm notice Beginning October 4, 2021, all connections to the npm registry - including ...

我今天照着 npm 文件,打算把自己开发的 npm 库发布到公网上:

npm login 之后,使用命名行 npm config set registry=http://registry.npmjs.org, 遇到如下错误:

npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm ERR! code E426
npm ERR! 426 Upgrade Required - PUT http://registry.npmjs.org/my-lib

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\I042416\AppData\Roaming\npm-cache_logs\2021-10-17T02_40_15_408Z-debug.log

大意是,从2021年10月4日开始,所有前往 npm registry 的连接,都需要使用 TLS 1.2 了.

因此,我把命名行改成使用 https,旧的错误消息就消失了:

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

然而我又遇到了新的错误消息:you do not have permission to publish “my-lib”. Are you logged in as the correct user?

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/my-lib - You do not have permission to publish “my-lib”. 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.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\I042416\AppData\Roaming\npm-cache_logs\2021-10-17T02_44_36_666Z-debug.log

这个错误的原因是,我在 package.json 里使用的库名称为 my-lib, 这是我从 npm 教程里照抄的,已经有人将同名的库上传到 npm 仓库去了,因此我没有权限上传一个同名的库。

将 package.json 里的 name 字段修改即可:

之后就能够成功上传库了:

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。