发布NPM包详细流程

制作

首先需要制作一个npm包。

按照以下步骤依次执行。

mkdir my-npm-package 
cd my-npm-package
npm init 

相信这一步不需要过多的解释,就是创建了一个文件夹,然后初始化了一下文件夹。

 然后在生成的package.json文件夹中更改一下自己的配置,例如包名、版本、描述等。

然后创建src文件夹,在对应的地方写下你自己的函数即可。

注册

npm也是一个平台,因此你需要在平台上注册一个账号,需要输入用户名,密码,以及一个邮箱号。

https://www.npmjs.com/signupicon-default.png?t=N7T8https://links.jianshu.com/go?to=https%3A%2F%2Fwww.npmjs.com%2Fsignup注册成功以后就可以登录了。当然这一步会遇到一些问题。比如:跳转到了cnpm

这是因为 npm的镜像地址有问题。所以这时候你需要将地址切换回来。

npm config set registry https://registry.npmjs.org/

登陆

注册完成以后,回到终端。执行以下命令。

npm adduser 

 再输入对应的账号密码邮箱就可以登录成功了。

发布

登陆成功以后在终端再次输入

npm publish .

看到这样的输出就算是上传成功了。

这时候再回到我们的NPM仓库就可以看到,已经有发布的包了。 

疑难问题解决

登陆不上

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 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/-/user/org.couchdb.user:xuzhonglin12138

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/guox/.npm/_logs/2024-08-01T09_18_16_117Z-debug-0.log

出现这样的报错说明你的set地址有问题。重新设置下地址。

注意!这里是https地址而不是http

npm config set registry https://registry.npmjs.org/

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大聪明码农徐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值