如何混合使用npm的公共仓库和cnpm搭建的私有仓库
发布于 8 年前 作者 ucoker 8965 次浏览 来自 问答

如何混合使用npm的公共仓库和cnpm搭建的私有仓库

问题详细在:https://github.com/cnpm/cnpmjs.org/issues/929

  • 在本地npm的账户,registry为 https://registry.npmjs.org/
    1. 安装在公共仓库的模块lodash,运行npm install lodash --save后,成功安装
    2. 安装在私有仓库的模块jsComponent,运行npm install [@cnpm](/user/cnpm)/jsComponent --save,提示错误'[@cnpm](/user/cnpm)/jsComponent' is not in the npm registry.
      此时的错误是因为我们没登录私有仓库引起的。
	```bash
	$ npm install [@cnpm](/user/cnpm)/jsComponent --save
	npm ERR! Darwin 15.4.0
	npm ERR! argv "/usr/local/Cellar/node/6.0.0/bin/node" "/usr/local/bin/npm" "install" "[@cnpm](/user/cnpm)/jsComponent" "--save"
	npm ERR! node v6.0.0
	npm ERR! npm  v3.8.6
	npm ERR! code E404
	
	npm ERR! 404 Not found : [@cnpm](/user/cnpm)/jsComponent
	npm ERR! 404 
	npm ERR! 404  '[@cnpm](/user/cnpm)/jsComponent' 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! Please include the following file with any support request:
	npm ERR!     /Users/admin/Tools/e/npm-debug.log
	```
  • 在本地登录私有仓库的帐户,registry为 https://r.mywebsite.com
    1. 执行$ npm login --registry=https://r.mywebsite.com --scope=[@cnpm](/user/cnpm),输入私有仓库的帐户密码后登录。
      成功登录,提示:Logged in as admin to scope [@cnpm](/user/cnpm) on https://r.mywebsite.com/.

    2. 安装在私有仓库的模块jsComponent,运行npm install [@cnpm](/user/cnpm)/jsComponent --save后,成功安装

    3. 安装在公共仓库的模块lodash,运行npm install lodash --save后,提示错误unauthorized login first: lodash

	```bash
	$ npm install lodash --save
	npm ERR! Darwin 15.4.0
	npm ERR! argv "/usr/local/Cellar/node/6.0.0/bin/node" "/usr/local/bin/npm" "install" "lodash" "--save"
	npm ERR! node v6.0.0
	npm ERR! npm  v3.8.6
	npm ERR! code E401
	
	npm ERR! unauthorized login first: lodash
	npm ERR! 
	npm ERR! If you need help, you may report this error at:
	npm ERR!     <https://github.com/npm/npm/issues>
	
	npm ERR! Please include the following file with any support request:
	npm ERR!     /Users/admin/Tools/e/npm-debug.log
	```

请教下,如何在登录私有仓库时,也可以成功通过scope来同步私有仓库,和公共仓库。或者能否同时登录npm的帐户和cnpm搭建的私有仓库帐户?

1 回复
回到顶部