第一次发布npm包踩的坑

第一次发布npm包遇到的一些坑,在这里记录一下

基本流程

初始化
npm init
登录npm

首先需要在npm上注册一个npm账号

npm login   // 或 npm adduser
发布
npm publish

遇到的问题

1、密码输入问题

执行npm login后,需要输入用户名,密码,邮箱,都是注册npm时候的信息,到输入密码时发现怎么都输入不上,以为是卡了,一番搞,发现是密码被隐藏了

npm notice Log in on https://registry.npmjs.org/
Username: xxxxxx
Password:
Email: (this IS public) xueling.xxx@163.com

输入密码时在password:后正常输入密码回车即可,可以正常登陆。
此处导致我一直疑问的原因是输入密码时虽然被隐藏了,但是鼠标占位符没有随着输入字符儿移动,给人感觉没输入上任何字符的感觉

2、npm 源不对
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmmirror.com/-/user/org.couchdb.user:xxxxxxxx - [FORBIDDEN] Public registration is not allowed
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.

原因:这个是你的源设置成第三方源的时候才有可能发生,比如设置了淘宝源就可能会导致该问题。只要把源改回默认的就可以了
解决方法:

  • 全局安装nrm 也就是node的源管理器
// 终端或者cmd中输入
npm install -g nrm
// 安装好以后 输入
nrm use npm  // 切换到npm官方的源地址

npm publish之后切换回来,正常安装包的时候可以使用nrm use taobao切换到淘宝镜像源

  • 切换源
npm config set registry http://registry.npmjs.org
3、版本号重复

假设我们在一个已发布的包中,且包未修改的情况下,重复执行npm publish。会出现以下错误提示

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/liwe-ui - You cannot publish over the previously published versions: 0.1.0.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.

原因:版本号未修改,与上次发布的版本一致
解决:更改package.json 配置:修改"version"属性值

4、无法发布私有包
npm ERR! code EPRIVATE
npm ERR! This package has been marked as private   // 即只有移除掉该属性才能发布
npm ERR! Remove the 'private' field from the package.json to publish it.

原因:因为这是一个私有项目
解决:更改package.json 配置:修改 private 属性值为 false 即可

"private": false

此外,如果不想每次新建项目都手动设置,可以进行全局配置

$ npm config set init-private true
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值