近期我接过了之前部门内部的一个开源包的的运维工作,业余时间解决一下开发者提的问题,所以又熟悉了一遍npm包的发布流程,大致如下:
- 去npm官网注册一个账号
- package的制作:
1.创建项目目录
2.打开命令行窗口在新建的项目目录下执行npm init 命令后, 按照要求填写package相关信息
npm login
遇到如下报错的话
npm ERR! network request to http://registry.cnpmjs.org/-/v1/login failed, reason: getaddrinfo ENOTFOUND registry.cnpmjs.org
直接在命令行做如下配置就好
npm config set registry http://registry.npmjs.org/
很多开发者在发布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/
则是因为从2021年10月4日开始,所有与npm网站和npm注册表的连接(包括软件包安装)必须使用TLS 1.2或更高版本。
可以使用以前命令安装相关环境
npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz
安装成功后会显示如下内容
Hello! The tls-test package was successfully downloaded and installed.
Congratulations! Your package manager appears to support TLS 1.2.
[email protected]
added 1 package from 1 contributor in 3.718s
然后就可以执行
npm login
npm publish
显示以下就表示package发布成功了,就可以去npm的官网上看到你发布的包了