发布npm包踩坑

40次阅读

共计 2336 个字符,预计需要花费 6 分钟才能阅读完成。

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

一:首先必须注册 npm 账号

用 npm adduser 命令

npm ERR! code EAUTHUNKNOWN
npm 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 publish
npm notice
npm notice package: lx@1.0.0
npm notice === Tarball Contents ===
npm notice 435B package.json
npm notice === Tarball Details ===
npm notice name:          lx
npm notice version:       1.0.0
npm notice package size:  324 B
npm notice unpacked size: 435 B
npm notice shasum:        60f600a893d64ddc1e71a4707c7de7f5974bcb01
npm notice integrity:     sha512-y16NeHDVs1aLk[...]WU0yjiaIvJD4g==
npm notice total files:   1
npm notice
npm ERR! code E403
npm ERR! 403 Forbidden - PUT http://r.cnpmjs.org/lx - [no_perms] Private mode  enable, only admin can publish this module
npm 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 publish
npm notice
npm notice package: lx@1.0.0
npm notice === Tarball Contents ===
npm notice 435B package.json
npm notice === Tarball Details ===
npm notice name:          lx
npm notice version:       1.0.0
npm notice package size:  324 B
npm notice unpacked size: 435 B
npm notice shasum:        60f600a893d64ddc1e71a4707c7de7f5974bcb01
npm notice integrity:     sha512-y16NeHDVs1aLk[...]WU0yjiaIvJD4g==
npm notice total files:   1
npm notice
npm ERR! code E403
npm 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,爽

正文完
 0