LOWINC / LOWINC.GitHub.io

通过预先定义的“组件”和“元素”拖拽生成页面
1 stars 0 forks source link

通过nexus建立npm私有仓库 #1

Open LOWINC opened 3 years ago

LOWINC commented 3 years ago

在nexus上配置npm私有仓库

新建三个仓库

仓库名称 作用 备注
npm-proxy 公共仓库代理 将代理地址设置为yarn源 https://registry.yarnpkg.com/
npm-hosted 本地 package.json
npm-group 聚合 .npmrc

项目设置

npm

package.json

"publishConfig": {
    "registry": "http://localhost:8888/repository/npm-hosted/"
},

业务

.npmrc

registry=http://localhost:8888/repository/npm-group/

用到的命令



命令 作用 说明
npm config list 查看npm配置 可以删token,改源
nrm ls nrm 源的管理工具
npm login -d registry=http://localhost:8888/repository/npm-group/ 登录xx仓库

先指定当前源

$ nrm add nexusNpm --- http://localhost:8888/repository/npm-group/
$ nrm use nexusNpm

登入

$ npm adduser

设置权限

Security -> Anonymous 添加登录的user


遇到的问题

登录报错:ENOTFOUND

npm login -d registry=http://localhost:8888/repository/npm-group/

npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to http://localhost:8888/repository/npm-group/-/v1/login failed, reason: getaddrinfo ENOTFOUND localhost

修复方法 编辑host文件 127.0.0.1 -> localhost

拉取推送时401

$ npm config list

/Users/apple/.npmrc

删除保存的_authToken

LOWINC commented 3 years ago

问题

npm ERR! code E400
npm ERR! 400 Bad Request - PUT http://localhost:8888/repository/npm-group/asddadad

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/apple/.npm/_logs/2021-08-13T08_03_26_105Z-debug.log

修改

  "publishConfig": {
    "registry": "http://localhost:8888/repository/npm-hosted/"
  },
LOWINC commented 3 years ago
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

401

LOWINC commented 3 years ago

指定默认源

$ nrm add nexusNpm --- http://localhost:8888/repository/npm-group/
$ nrm use nexusNpm
LOWINC commented 2 years ago

anonymous

禁止匿名用户访问后 推送报错401

由于npm仓库设置了禁止匿名访问,所以在本地登录。

npm adduser --registry=http://localhost:10088/repository/npm-hosted/
npm-dev-1
sunweiqi
123@qq.com

参考

LOWINC commented 2 years ago

npm Security If enabled, any anonymous user has read access to the repositories and repository groups. If anonymous access, as documented in Anonymous Access, is disabled or write access is required for publishing a package, the user needs to authenticate to the repository manager. There are two methods to authenticate npm with your repository manager. Only one should be used at a time.

Authentication Using Realm and Login This authentication method requires the npm Bearer Token Realm. Simply add the realm to the active realms in the Realms feature of the Security menu from the Administration menu to activate it as documented in Realms.

Once the realm is activated, a npm CLI user can establish the authentication to a repository with the npm adduser ( npm login is an equivalent alias ) command.

npm adduser --registry=http://localhost:8081/repository/npm-hosted/ Provide your repository manager username and password as well as an email address when prompted. Upon successful completion, a line for authentication of this combination is automatically added to your .npmrc configuration file for the specific repository.

Despite its name, the npm adduser command does not actually create a user account inside NXRM. It merely associates a token with an existing user account and allows the CLI to store that token for re-use.

LOWINC commented 2 years ago

设置私服后 yarn 安装报错:Couldn't find package "lodash-es" on the "npm" registry.

/Users/apple/.npmrc

设置:

always-auth=true