1. 注册账号 https://www.npmjs.com/

2. 验证邮箱 (邮箱一定要验证通过,不然后面会出错)

3. 整理你本地的项目

  1. package.json 文件中 "private": true 一定去掉

4. 登陆你 npm 账号

  1. npm adduser
  2. or
  3. npm login
  4. ## 需要输入你的账号、密码、邮箱

5. 发布你的项目

  1. npm publish

6. 可能会出现的错误

  1. 问题一,镜像问题 ```git npm ERR! code E403 npm ERR! 403 Forbidden - PUT https://registry.npm.taobao.org/lld-npm-demo - no_perms

npm ERR! A complete log of this run can be found in:


解决方案:

```git
// 检查仓库是否被设成了淘宝镜像库(https://registry.npm.taobao.org/)
npm config get registry

// 如果设置了淘宝镜像,执行以下命令
npm config set registry=http://registry.npmjs.org

// 解决问题后重新发布
npm publish

// 发布成功以后,在设会淘宝镜像
npm config set registry=https://registry.npm.taobao.org/
  1. 问题二:邮箱未验证

image.png

解决方案:

去邮箱验证,注意邮箱是不是给屏蔽了,垃圾邮箱里面也看看

  1. 问题三:账号未登陆
npm ERR! code E401
npm ERR! 401 Unauthorized - PUT http://registry.npmjs.org/lld-npm-demo - You must be logged in to publish packages.
  1. 问题四: 版本号
npm ERR! code E403
npm ERR! 403 Forbidden - PUT http://registry.npmjs.org/lld-npm-demo - You cannot publish over the previously published versions: 1.0.0.
  1. 问题5:

解决方法:

npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz npm config set registry https://registry.npmjs.org

npm notice 
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/your-packageName

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/leglo/.npm/_logs/2021-11-22T05_01_07_569Z-debug.log