我已经安装了 nexus oss 3,它看起来很酷。由于 --pure-lockfile 选项,我所有的项目都是使用 yarn 安装的。
重现问题的步骤:
1. 使用私有(private) npm 注册表设置 nexus oss 3(如文档中所示)
2. 从 nexus oss 3 管理面板禁用匿名访问
3. 在带有 alpine 的 linux 服务器上尝试 yarn install --pure-lockfile(你必须有一个包托管在 package.json 的私有(private)仓库中)
4.不起作用,返回401错误
我尝试了一切,但我无法让 yarn 登录以获取这些包。
如果我使用 npm install,它会起作用。
谁能告诉我如何使用上面的设置让 yarn 工作在 nexus oss3 上?
最佳答案
如果 npm install
正常工作,那么您必须正确定义登录凭据和存储库。
- 打开终端并运行
npm login
,为 nexus 帐户提供您的用户名和密码。这将创建一个文件~/.npmrc
。打开这个文件nano ~/.npmrc
,输出看起来像
//<repository>:_authToken=NpmToken.<token>
一个虚拟的例子:
//test.server.com/repository/npm-group/:_authToken=NpmToken.123456-12345-12345-tok-en0onum
- 进入项目目录
cd <project_dir>
,新建文件.yarnrc
,打开nano .yarnrc
。插入以下行,保存并退出(Ctrl+O, Ctrl+X)。
registry "<repository>"
- 在同一目录
.npmrc
中创建另一个文件<project_dir>
。打开,添加以下行,保存并退出。
registry=<repository>
always-auth=true
//<repository>:_authToken=NpmToken.<token>
删除主目录
.npmrc
中的rm ~/.npmrc
。现在您可以使用
node_modules
或yarn
下载yarn install
。
关于npm - 如何在 Sonatyoe Nexus OSS 中使用带有私有(private) npm 注册表的 yarn ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43849946/