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

JerryWang_汪子熙 -
npm publish 发布一个 Angular 库的时候报错以及解决方法

我今天照着 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-2...
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... - 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 字段修改即可:

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

更多Jerry的原创文章,尽在:"汪子熙":

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

npmnode.jsjavascript前端angular

扩展阅读

加个好友,技术交流

1628738909466805.jpg