昨天试着发布npm包,遇到了问题,记录一下。

一:首先必须注册npm账号

用npm adduser 命令

npm ERR! code EAUTHUNKNOWNnpm ERR! Unable to authenticate, need: Basic
把npm升级到6.9.0 ,报另一个错
    npm ERR! code E401    npm ERR! Incorrect or missing password.    npm ERR! If you were trying to login, change your password, create an    npm ERR! authentication token or enable two-factor authentication then    npm ERR! that means you likely typed your password in incorrectly.    npm ERR! Please try again, or recover your password at:    npm ERR! https://www.npmjs.com/forgot    npm ERR!    npm ERR! If you were doing some other operation then your saved credentials are    npm ERR! probably out of date. To correct this please try logging in again with:    npm ERR!     npm login 

继续百度,表面看样子是我密码不正确,其实因为重定向了npm库的源,所以npm adduser时会将用户名和密码提交到http://registry.npm.taobao.org 去验证

于是切源 到cnpm。

继续npm adduser,这次就有用户名、邮箱的提示。

最后一句话看样子是成功了

执行命令 npm publish 发布

结果报错

$ npm publishnpm noticenpm notice package: lx@1.0.0npm notice === Tarball Contents ===npm notice 435B package.jsonnpm notice === Tarball Details ===npm notice name:          lxnpm notice version:       1.0.0npm notice package size:  324 Bnpm notice unpacked size: 435 Bnpm notice shasum:        60f600a893d64ddc1e71a4707c7de7f5974bcb01npm notice integrity:     sha512-y16NeHDVs1aLk[...]WU0yjiaIvJD4g==npm notice total files:   1npm noticenpm ERR! code E403npm ERR! 403 Forbidden - PUT http://r.cnpmjs.org/lx - [no_perms] Private mode  enable, only admin can publish this modulenpm ERR! A complete log of this run can be found in:npm ERR!      C:\Users\zt\AppData\Roaming\npm_cache\_logs\2019-05-14T07_59_28_430Z-debug.log

cnpm源发布时说我源不正确

于是我又把npm切换回npm,npm源发布时报错

意思说必须登录才能发布包,emmmmm......

于是简单粗暴,我去npm.js官网手动注册 https://www.npmjs.com/

手动注册---然后npm login登录

继续发布 又报错:因为名字重复了(报错:You do not have permission to publish "lx")

$ npm publishnpm noticenpm notice package: lx@1.0.0npm notice === Tarball Contents ===npm notice 435B package.jsonnpm notice === Tarball Details ===npm notice name:          lxnpm notice version:       1.0.0npm notice package size:  324 Bnpm notice unpacked size: 435 Bnpm notice shasum:        60f600a893d64ddc1e71a4707c7de7f5974bcb01npm notice integrity:     sha512-y16NeHDVs1aLk[...]WU0yjiaIvJD4g==npm notice total files:   1npm noticenpm ERR! code E403npm ERR! 403 Forbidden - PUT https://registry.npmjs.org/lx - You do not have  permission to publish "lx". Are you logged in as the correct user?npm ERR! A complete log of this run can be found in:npm ERR!      C:\Users\zt\AppData\Roaming\npm_cache\_logs\2019-05-14T08_29_28_668Z-debug.log
lx名字被占用,改成lx-zt 继续发布,又报错:(you must verify your email before publishing a new package: https://www.npmjs.com/email-edit) 意思是邮箱没有验证

注册之后要去邮箱验证

终于终于终于成功了
有这句话就算成功了:+ lx-zt@1.0.0

然后我就可以在其他项目安装我的lx-zt,爽