npm|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! A complete log of this run can be found in:
npm ERR! code E426
npm ERR! 426 Upgrade Required - PUT http://registry.npmjs.org/my-lib
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 E403npm ERR! A complete log of this run can be found in:
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! 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 字段修改即可:
文章图片
之后就能够成功上传库了:
文章图片
文章图片
【npm|npm publish 发布一个 Angular 库的时候报错以及解决方法】更多Jerry的原创文章,尽在:"汪子熙":
文章图片
推荐阅读
- 图文小编《杨浦、成毅》为你发布!无价之宝随意摆放的公园
- 用npm发布一个包的教程并编写一个vue的插件发布
- 【译】Rails|【译】Rails 5.0正式发布(Action Cable,API模式等)
- 运用flutter|运用flutter 构建一个发布版(release)APK
- Vue组件之事件总线和消息发布订阅详解
- K8S|K8S 生态周报| Istio 即将发布重大安全更新,多个版本受影响
- Redis——发布订阅/消息队列
- LOGO--完美世界Logo设计(三)
- 这款充电最快的5G手机就要发布了,你对它还一无所知()
- 解放全球宝妈,宝倍爽发布“纸尿裤3.0”开启母婴智能新生活