技术干货Web 前端开发

搭建cnpm遇到的那些坑儿

2018-05-31  本文已影响5人  Eugeneeee

搭建cnpm私有库之后,针对发布私有包和install私有包时可能遇到的坑。

npm login   // OR cnpm login
Username: xxxx
Password:
Email: (this IS public) xxx@xxx.com
Logged in as xxx on http://xxxxxxx/.

登录成功。但是发布私有包却报错,npm publish:

npm ERR! publish Failed PUT 401
npm ERR! code E401
npm ERR! 404 unauthorized Login first: <package>
npm ERR! 404
npm ERR! 404  '<package>' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/eugene/.npm/_logs/2018-05-30T08_12_38_183Z-debug.log

此处发包碰到此问题的原因可能会出现以下几点:

  1. npm 源设置的不对,需要重新npm config set registry https://xxxxxxx
  2. npm 源正确设置,登录成功,但是发包一直401。这时如果找不到问题所在,切换至cnpm会有意想不到收获。设置cnpm源,并使用cnpm login,然后cnpm publish。

对于cnpm install 会碰到的问题:

cnpm install <package> 的时候一直retry,最后报ResponseError: socket hang up (req "error")。

解决方案:在config/index.js里有个配置,我看到的所有文章都没有提到。

// registry url name
registryHost: 'r.cnpmjs.org', // 修改成你自己服务器host。

上一篇下一篇

猜你喜欢

热点阅读