<p>yarn不支持.npmrc中的身份验证设置</p>

创建于 2017-09-14  ·  86评论  ·  资料来源: yarnpkg/yarn

您是否要请求功能或报告错误
臭虫
目前的行为是什么?
纱线不支持.npmrc
如果当前行为是错误,请提供重现步骤。
我们需要对其中一个存储库进行身份验证,而我们过去通常通过在.npmrc中指定身份验证来进行身份验证。 最高达到0.28.4,但最终达到1.0.0

预期的行为是什么?
遵守.npmrc中的身份验证设置

请提及您的node.js,yarn和操作系统版本。
在将yarn升级到1.0.0 / 1.0.1(尝试过两个版本)之后,就会发生这种情况。 不论OS和nodejs版本如何。

cat-bug help wanted

最有用的评论

此问题已在2017年报告,现在是2019年,此问题仍然存在。

所有86条评论

该问题应在昨天发布的1.0.2中修复。 你可以试一下吗?

@BYK我遇到了与#4157末尾提到的相同的问题。 我尝试运行1.0.2并失败了404 。 在0.27.5运行符合预期。

您能在这里粘贴您的npmrc文件,以便我们尝试重现(显然是删除秘密或其他私人信息)

@KidkArolis尝试使我的工作目录尽可能干净时,它以某种方式解决了该问题? 🙃

我采取的步骤:

  • 删除yarn.lock和任何yarn-error.log文件
  • 删除node_modules/
  • brew link yarnyarn --version以确保我的身价为1.0.2
  • yarn

这似乎奏效了。 我会把这归结为我和我团队的用户错误。

@beardedtim如果您现在吹走node_modules但保留yarn.lock然后运行yarn install怎么办? 那全部有用吗? 这部分是#4157跟踪的内容,但可能与手头较大的问题有关?

对于纱线版本1.0.1和1.0.2,我遇到了这个问题(在私有范围的仓库中使用404,无论我使用哪个注册表)。 清除一些瑕疵后,版本0.27.5即可正常工作。

我已经尝试了https://github.com/yarnpkg/yarn/issues/4157中讨论的所有解决方法

@stieg今天

有没有人找到解决方案?

FWIW:我尝试过:

  • 清除我的node_modules
  • 清除~/.yarn
  • curl -o- -L https://yarnpkg.com/install.sh | bash重新安装yarn 1.0.2
  • yarn install -_没有错误_,它完美安装了所有内容。

我的~/.yarnrc

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


registry "https://registry.npmjs.org"
email [email protected]
lastUpdateCheck 1505977814820
username some-user
````

And my `~/.npmrc`:

//registry.npmjs.org/:_authToken=a-valid-uuid


The `yarn.lock` references look like this in my particular case:

解决了“ https://registry.npmjs.org/@acme/some -module /-/ some-module-0.1.1.tgz#valid-git-sha”
```

有趣。 将注册表放入我的.yarnrc文件后,我能够安装我的软件包。 但是,我删除了它以检查是否是罪魁祸首,并且仍然成功(我删除了缓存,因此Yarn必须下载它,并且它能够正确地做到这一点)。

我尝试了全新安装(这次是Debian,另一个是macOS),并且在~/.npmrc~/.yarnrc使用这些设置在这里同样有效。 (注意:我没有尝试npm loginyarn login 。)

有人报告此事后结案已解决。 如果您无法解决,请重新打开具体的复制步骤,

@BYK我有同样的问题。
我使用了最新版纱线的全新安装。
在我将registry "https://registry.npmjs.org"~/.yarnrc之后,它开始工作。
我认为这是一个错误,应该像我们一样自动解决,而不要手动解决。

@BYK可能需要注意,每个“报告为已解决”的人都使用了强制执行yarn来使用https://registry.npmjs.org注册表的解决方法。

我认为从https://registry.yarnpkg.com注册表检索私有软件包仍然存在问题,但这是yarn使用的默认注册表(它仍然只是反向代理吗?也许它不遵循auth标头? )。

具体的复制步骤

  1. 删除/移动.npmrc.yarnrc文件,以便yarn使用默认配置。
  2. 找到私有发布到npm注册表的软件包。
    1a。 如果您是从与测试纱线相同的机器上下载/发布的,请清除npm和纱线缓存。
  3. 运行npm loginyarn login来填充身份验证令牌。
  4. 使用0.27.5之后的任何yarn版本,尝试安装此软件包。
预期成绩

软件包安装成功。

实际结果
❤ <strong i="26">@up</strong> ➜  REPO git:(master) ★ yarn add @SCOPE/PACKAGE 
yarn add v1.1.0
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.npmjs.org/@SCOPE%2fPACKAGE: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/home/katy/dev/REPO/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

如果项目维护者发现@kmoe的说明是可复制的,则应重新打开此票证(至少出于现有订户的考虑)。

@kmoe同意,潜在的问题甚至没有在最新版本的纱的固定。 请重新打开问题。 是的,我们有一种解决方法,但是在这种情况下,解决方法!=解决方案。

FWIW,这在1.1.0中仍然是一个问题。 我刚刚对其进行了验证(返回此处获取解决方法,即将registry "https://registry.npmjs.org"添加到~/.yarnrc

我在yarn 1.3.2中遇到了这个问题,它现在正在破坏我们的构建。 在0.27.5的纱线上效果很好。

我们需要.npmrc文件中的auth令牌才能从Artifactory专用注册表中安装软件包。

复制步骤:

  1. 有一个.npmrc文件,其中包含身份验证信息,例如:
registry=https://artifactory.mycompany.com/artifactory/api/npm/npm-virtual
_auth = myAuthTokenHere
always-auth = true
email = [email protected]
  1. 运行yarn install
  2. 当yarn尝试从私有注册表中安装内容时,出现HTTP 401错误:
error An unexpected error occurred: "https://artifactory.mycompany.com/api/npm/npm-virtual/@angular/compiler/-/compiler-4.3.1.tgz: Request failed \"401 Unauthorized\"".

相关:#4672

@stewx我在1.3.2上也遇到同样的问题。 您找到解决方法或解决方法了吗?

@jamesone不,我降级为0.27。 这是我们项目的一个突破。

@stewx @jamesone
在您的.yarnrc中添加registry "https://registry.npmjs.org"并重新安装私有软件包
它将告诉yarn直接与npmjs注册表一起使用,它将解决该问题

只是为了避开这一问题而将版本锁定在0.27.5感觉太不正确了,但是似乎许多人正在做_or_重定向registry配置(尽管@stewx报告无法解决自托管问题)私人注册表)。

如果频繁的项目贡献者没有时间在短期内解决此问题,是否有人愿意建议最有可能成功解决的代码库位置,以希望能够开放社区PR? 🤔

/立方厘米@kittens @bestander @BYK @arcanis @ rally25rs @kaylieEB

@Bnaya当您说重新安装时,您是说要删除项目中的node_modules还是清除纱线缓存?

纱去掉你的私人包装; 纱添加您的私人包裹

在锁定文件中,您将看到https://registry.npmjs.org/***网址,而不是https://registry.yarnpkg ***

我建议在您的package.json旁边添加.yarnrc

我实际上是通过将registry "https://registry.npmjs.org"放入~/.yarnrc ,即不需要本地.yarnrc

为我重现错误的步骤:

  • 没有修改的~/.yarnrc
  • 创建新项目
  • 纱线存放清洁
  • 纱线添加privatemodule->失败

如果我如上所述修改~/.yarnrc ,则步骤不会产生错误。

如果我查看项目中某些失败的地方,我会看到yarn.lock包含https://registry.yarnpkg.com/@myscope/mypackage/ 。 为了使这些项目正常工作,我需要在更新到./.yarnrc之后删除yarn.lock并重新生成它。

这似乎可以解释为什么有些人即使尝试了对其他人有用的东西,仍然会有错误。

结论如何解决:

  • registry "https://registry.npmjs.org"到〜/ .yarnrc
  • 为失败的项目删除并重新生成yarn.lock

@TheLudd从头开始重新生成yarn.lock失败了。

相反,项目维护人员可能希望考虑从yarnpkg.comnpmjs.org进行搜索/替换, yarnpkg.com保留其当前的锁定文件状态。

@awkaiser好吧,只要您的测试通过,就可以提交它,其他所有协作者都将拥有与您相同的环境。 因此,IMO并没有真正实现其宗旨。
但是,您也可以搜索替换。

但是规则还在于,您不应该手动修改yarn.lock;)

如果总是安全地提取满足package.json要求的绝对最新的软件包,则根本不需要锁文件。 😜

通常,是的,我们不应该手工修改yarn.lock ,但这是一个错误,它支持该规则的异常。 通过搜索和替换来更新注册表位置参考应该是直接且安全的。 🍻

我不需要重新生成整个锁定文件。
只是删除并安装私人软件包

@awkaiser或线程中的任何其他人-您可以提供帮助的一种方法是创建一个可复制的示例。 例如,以该仓库为基础https://github.com/KidkArolis/yarn-scopes-issue。 如果您可以在运行yarn失败(特定的注册表响应,特定的yarn配置,特定的package.json等)的地方生成一个仓库,那么我绝对可以着手解决此问题。

通常:

  1. 您不需要.yarnrc文件
  2. 您不需要.yarnrc即可包含registry "https://registry.npmjs.org"
  3. registry.npmjs.org私有模块应该可以工作
  4. custom.registry.org私有模块应该可以工作

@KidkArolis失败是随机的。 但他们在那里。
正如我在另一个相关问题上所写的那样:它或纱线注册表的问题(可能是缓存失败,代理上的Vary标头不正确,无论如何),或纱线内部复杂的边缘情况(仅发生在纱线注册表中)。

@kmoe在2017年9月25日写的

它提示重新打开此问题,这意味着要由贡献者进行复制。

@KidkArolis我不确定如何在存储库中创建可重现的示例,因为这涉及私有模块,因此取决于谁运行yarn,对吗? 但是我要重现该错误的步骤是在这里https://github.com/yarnpkg/yarn/issues/4451#issuecomment -355248563并且@kmoe编写的内容也足够。

当我尝试安装私有软件包而不修改.yarnrc ,我得到的错误是

发生意外错误:“ https://registry.yarnpkg.com

这意味着它在纱线注册表中查找,而不是npm。 那不是导致此错误的错误吗?

好的,感谢您重新安排这些复制步骤。 我会尝试看看。

无论出于何种原因,将此显式位置添加到.npmrc中以查找我的私有软件包的位置使404错误停止在所有引起问题的存储库上发生。

@npm-username:registry=https://registry.yarnpkg.com/

有没有人可以将我添加到私人npm软件包中? 用户名: kidkarolis

我正在努力获得一个付费帐户,他们的帐单/帐户系统似乎对我的atm无效(即使他们向我收取费用,我也会得到402 Payment Required :-“)。因此,当我等待npm的时候支持,如果有人将我添加到私有软件包中(即使有可能),那将会加快速度。

好的,我认为这只是..最终的一致性,我的私人npm帐户现在可以使用了。

但是,我还不能重现问题:(

我遵循@kmoe提供的步骤:

  1. rm ~/.yarnrc && rm ~/.npmrc
  2. yarn cache clean && npm cache clean --force
  3. npm login
  4. yarn add @scope/pkg

它安装得很好(如果我不npm login也不会)。 换句话说-符合我的预期。

从yarn.lock判断,我的安装过程通过https://registry.yarnpkg.com并且似乎按预期使用auth。 过去服务器上可能有问题,但现在已解决了吗?

好的,我认为是复制了一些东西。

如果我将<strong i="6">@qubit</strong>:registry=https://registry.npmjs.org/.npmrc -安装将不再起作用。
我认为,如果您使用npm login --scope=@qubit登录,则会添加该行;如果仅使用npm login登录,则不会添加该行。 接下来将看到如何解决此问题。

@KidkArolis设置该配置的其他常用方法是:

npm config set <strong i="8">@qubit</strong>:registry https://registry.npmjs.org

开启了PR-#5162反馈(甚至QA)咨询。

@KidkArolis感谢您的公关。 但是我认为问题不仅在于“ --scope”情况,还在于更普遍的情况,即私有仓库也使用auth镜像公共包。

顺便说一下, @ bytheway875 ,使用https://registry.yarnpkg.com/作为注册表的技巧对我有用

我的情况:

  • 目标:在CI构建(GitLab)期间,使用本地.npmrc文件中的authToken从npmjs.com上的组织(@ org-name)用yarn安装私有软件包,因此不要登录npm
  • npm
  • 开发机(mac)上没有问题,我可以npm loginyarn正常工作,或者我可以退出npm,但可以手动创建本地/ HOME目录.npmrc文件,一行: //registry.npmjs.org/:_authToken=tokenyarn才有效(第二种方法_might_是本地缓存的工作原因,没有尝试清除它)
  • .yarnrc招不起作用

_我要使其工作的唯一方法是在CI中运行yarn install之前创建以下本地.npmrc文件:_

@org-name:registry=https://registry.yarnpkg.com/
always-auth=true
_authToken=token

.npmrc文件有类似问题。 我要做的只是将.npmrc文件的编码设置为ANSI(在Windows中,您可以使用notepad.exe>另存为...)。
您可以使用yarn config list来测试yarn如何查看.npmrc文件内容

我无法将其与v1.4.1 。 我有一个私人Nexus回购协议,并将其用作缓存/代理(例如)。 我似乎找不到明确的说明,因此我可能做错了什么。 我在这里获取了yarn config语法,在这里获取yarn login语法

编辑:我应该提到我曾尝试通过NPM登录以获得所需的.npmrc然后再尝试使用yarn

以下正是我要测试的内容。

检查合并提交(dc705768)

git tag --contains dc705768
v1.4.0
v1.4.1

设定

创建一个Dockerfile以提供一致的基准测试环境。

# Build
#  docker build -t yarn-private-registry-test .
# Run
#  docker run -it --rm yarn-private-registry-test

FROM debian:9.3-slim

WORKDIR /projects

RUN apt-get update \
  && apt-get --yes install curl gnupg \
  && curl -sL https://deb.nodesource.com/setup_8.x | bash - \
  && apt-get install --yes nodejs \
  && curl -OL https://github.com/yarnpkg/yarn/releases/download/v1.4.1/yarn_1.4.1_all.deb \
  && find . -name yarn*.deb -exec dpkg --install {} \; \
  && find . -name yarn*.deb -exec rm {} \;

构建Docker映像

docker build -t yarn-private-registry-test .

测试纱

提示:继续退出并重新启动Docker容器以获得干净的环境。

没有配置

通过初始化项目并添加依赖项而不进行任何配置更改来确保环境正常运行。

运行Docker容器

docker run -it --rm yarn-private-registry-test

测试

添加left-pad依赖性。

mkdir yarn \
  && cd yarn \
  && yarn init --yes \
  && yarn add left-pad
yarn init v1.4.1
warning The yes flag has been set [...snip...]
success Saved package.json
Done in 0.03s.
yarn add v1.4.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
└─ [email protected]
Done in 0.52s.

专用注册表配置

运行Docker容器

docker run -it --rm yarn-private-registry-test

测试

mkdir yarn \
  && cd yarn \
  && yarn init --yes \
  && yarn config set registry https://example.com/repository/npm-group/ \
  && yarn login
yarn init v1.4.1
warning The yes flag has been set [...snip...]
success Saved package.json
Done in 0.03s.
yarn config v1.4.1
success Set "registry" to "https://example.com/repository/npm-group/".
Done in 0.04s.
yarn login v1.4.1
question npm username: myusername
question npm email: [email protected]
Done in 6.25s.

添加left-pad依赖性。

yarn --verbose add left-pad
yarn add v1.4.1
verbose 0.349 Checking for configuration file "/projects/yarn/.npmrc".
verbose 0.35 Checking for configuration file "/usr/local/share/.npmrc".
verbose 0.35 Checking for configuration file "/usr/etc/npmrc".
verbose 0.352 Checking for configuration file "/root/.npmrc".
verbose 0.353 Checking for configuration file "/projects/yarn/.npmrc".
verbose 0.353 Checking for configuration file "/projects/.npmrc".
verbose 0.355 Checking for configuration file "/projects/yarn/.yarnrc".
verbose 0.355 Checking for configuration file "/usr/local/share/.yarnrc".
verbose 0.357 Found configuration file "/usr/local/share/.yarnrc".
verbose 0.358 Checking for configuration file "/usr/etc/yarnrc".
verbose 0.358 Checking for configuration file "/root/.yarnrc".
verbose 0.359 Checking for configuration file "/projects/yarn/.yarnrc".
verbose 0.359 Checking for configuration file "/projects/.yarnrc".
verbose 0.365 current time: 2018-01-25T21:55:48.886Z
info No lockfile found.
verbose 0.405 Performing "GET" request to "https://yarnpkg.com/latest-version".
[1/4] Resolving packages...
verbose 0.48 Performing "GET" request to "https://example.com/repository/npm-group/left-pad".
verbose 0.52 Request "https://example.com/repository/npm-group/left-pad" finished with status code 401.
verbose 0.522 Error: Couldn't find package "left-pad" on the "npm" registry.
    at new MessageError (/usr/share/yarn/lib/cli.js:186:110)
    at NpmResolver.<anonymous> (/usr/share/yarn/lib/cli.js:50354:15)
    at Generator.next (<anonymous>)
    at step (/usr/share/yarn/lib/cli.js:98:30)
    at /usr/share/yarn/lib/cli.js:109:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
error An unexpected error occurred: "Couldn't find package \"left-pad\" on the \"npm\" registry.".
info If you think this is a bug, please open a bug report with the information provided in "/projects/yarn/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
verbose 0.809 Request "https://yarnpkg.com/latest-version" finished with status code 200.

检查.yarnrc

cat /usr/local/share/.yarnrc
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


registry "https://example.com/repository/npm-group/"
email [email protected]
lastUpdateCheck 1516917349331
username myusername

测试NPM

直接跳到所需的配置,因为它可以工作。

专用注册表配置

运行Docker容器

docker run -it --rm yarn-private-registry-test

测试

mkdir npm \
  && cd npm \
  && npm init --yes \
  && npm config set registry https://example.com/repository/npm-group/ \
  && npm login
Wrote to /projects/npm/package.json:

{
  "name": "npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


Username: myusername
Password:
Email: (this IS public) [email protected]
Logged in as myusername on https://example.com/repository/npm-group/.

添加left-pad依赖性。

npm --verbose install left-pad
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli   '/usr/bin/npm',
npm verb cli   '--verbose',
npm verb cli   'install',
npm verb cli   'left-pad' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session 0ed36c84804378c8
npm http fetch GET 200 https://example.com/repository/npm-group/left-pad 78ms
npm http fetch GET 200 https://example.com/repository/npm-group/left-pad/-/left-pad-1.2.0.tgz 28ms
npm verb correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
npm verb makeDirectory /root/.npm/_locks creation not in flight; initializing
npm verb lock using /root/.npm/_locks/staging-2f9f45630e5bbb1a.lock for /projects/npm/node_modules/.staging
npm info lifecycle [email protected]~preinstall: [email protected]
npm info linkStuff [email protected]
npm verb linkBins [email protected]
npm verb linkMans [email protected]
npm info lifecycle [email protected]~install: [email protected]
npm info lifecycle [email protected]~postinstall: [email protected]
npm verb unlock done using /root/.npm/_locks/staging-2f9f45630e5bbb1a.lock for /projects/npm/node_modules/.staging
npm verb saving [ { name: 'left-pad', spec: '^1.2.0', save: 'dependencies' } ]
npm info lifecycle undefined~preshrinkwrap: undefined
npm info lifecycle undefined~shrinkwrap: undefined
npm notice created a lockfile as package-lock.json. You should commit this file.
npm info lifecycle undefined~postshrinkwrap: undefined
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
added 1 package in 0.398s
npm verb exit [ 0, true ]
npm info

@ryanjaeb感谢您的详细报告。 为了告诉您这里可能出了什么问题,我想念的一件事是~/.npmrc~/.yarnrc文件的内容。 您确实粘贴了.yarnrc ,但其中不包含密码。 同样也没有.npmrc文件进行比较,很难指出问题所在。

您的用例在^ 1.4.0中应该可以正常工作,但这全都与配置文件的外观有关。

和您在一起,我从不使用yarn login ,我先使用npm login然后再使用yarn 。 在你上面的例子,如果你先做npm set config registry ... && npm login 然后运行add left-pad -它的工作原理? 如果npm有效,则应使用纱线。 所以我想知道yarn login命令是否已损坏。

@KidkArolis通过忽略yarn login并期望能够仅使用npm login使其工作,我得以取得一些进步。 我看到两件事。

.npmrc

npm-login的文档似乎与我在.npmrc实际看到的不匹配。 具体来说, npm login命令的--always-auth arg对配置没有影响,即使文档说:

可以与--registry和/或--scope一起使用,例如
...
Always-auth的特定于注册表的配置优先于任何全局配置。

但是,无论我是否使用该参数,我总是以相同的.npmrc结尾。 都:

npm config set registry https://example.com/repository/npm-group/ \
  && npm login --registry=https://example.com/repository/npm-group/

npm config set registry https://example.com/repository/npm-group/ \
  && npm login --registry=https://example.com/repository/npm-group/ --always-auth

产生这个.npmrc

registry=https://example.com/repository/npm-group/
//example.com/repository/npm-group/:_authToken=NpmToken.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

嗅探去往我的注册表的流量显示NPM发送auth令牌,无论:

GET /repository/npm-group/left-pad HTTP/1.1
Host: example.com
user-agent: npm/5.6.0 node/v8.9.4 linux x64
npm-in-ci: false
npm-scope: 
npm-session: c4c14c0b37be7bd5
referer: install left-pad
pacote-req-type: packument
pacote-pkg-id: registry:manifest
accept: application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*
authorization: Bearer NpmToken.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
accept-encoding: gzip,deflate
X-Forwarded-Proto: https
X-Forwarded-For: 10.10.10.1
X-Forwarded-Host: example.com
X-Forwarded-Server: example.com
Connection: Keep-Alive

纱线发送令牌,除非always-auth设置。 在.npmrc显式设置always-auth标志可以使一切正常工作。

npm config set always-auth true \
    && cat ~/.npmrc
registry=https://example.com/repository/npm-group/
//example.com/repository/npm-group/:_authToken=NpmToken.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
always-auth=true

除了知道NPM和Yarn之间的行为不同之外,我都不熟悉哪种行为是正确的。

yarn login

我认为您可能对yarn login无法正常使用是正确的,但是我还没有对其进行广泛的测试。 忽略.npmrc使用yarn ,我尝试模仿NPM配置。

yarn config set registry https://example.com/repository/npm-group/ \
    && yarn config set always-auth true \
    && yarn login

.yarnrc

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


registry "https://example.com/repository/npm-group/"
always-auth true
email [email protected]
lastUpdateCheck 1517883362958
username myusername

无论我做什么,都不会提示我输入密码。

@KidkArolis对我来说,npm在.npmrc中没有显式always-auth=true情况下工作,而yarn(1.3.2或1.4.0)则没有。 在我的情况下,我试图将所有请求都指向虚构中的虚拟注册表。 在.npmrc中有always-auth=trueauthToken ,它可以在1.3.2 ,因此不清楚在1.4.0到底是什么固定。

这似乎仍然是一个问题,特别是连接到我们的Nexus存储库。

我尝试了几种方法:

  1. 完全删除我的~/.yarnrc并仅依赖~/.npmrc
  2. 嘲笑~/.yarnrc注册表设置。

似乎纱线没有使用散列_auth值(例如_auth=xyz从) ~/.npmrc

版本信息

NPM

npm --version                                                                                                                                                                                                                                                                                                      
5.6.0

yarn --version
1.5.1

在OS X 10.13.2上运行。

NPMRC

我的~/.npmrc看起来像这样(出于明显的原因,省略了一些设置_values_):

registry=http://nexus-repo:8081/content/repositories/npm-all
init.author.name=Juan Smith
[email protected]
init.author.url=http://nexus-repo:8081/content/repositories/npm/
[email protected]
_auth=BASE64-HASH-USERNAME-PASSWORD
always-auth=true

纱网

我的~/.yarnrc看起来像这样(再次省略了明显的值):

registry "http://nexus-repo:8081/content/repositories/npm-all//"
email [email protected]
lastUpdateCheck 1521495247797
username jsmith

¯_(ツ)_ /¯

不太确定从这里去哪里。 目前尚不清楚发生了什么,除了所有纱线的制造都以以下方式失败:

error An unexpected error occurred: "http://nexus-repo:8081/content/groups/npm-all/lru-cache/-/lru-cache-4.1.2.tgz: Request failed \"401 Unauthorized\"".

FWIW,IANADOE(我不是开发运营工程师),只是想利用一种依靠纱线的包装来构建电子。 这可能只是我不知道如何为yarn设置base64 username | password哈希。 我找不到能解释这一点的文档。

@ezweave Sonatype有非常好的文档。 该链接还包含有关测试的说明,以确保您正确执行了base64编码。 我个人认为在Nexus中启用npm Bearer Token Realm并在工作站上使用npm login最简单。 例如:

npm config set registry http://nexus-repo:8081/content/repositories/npm-all
npm login --registry=http://nexus-repo:8081/content/repositories/npm-all --always-auth
npm config set always-auth true

在尝试使用Yarn之前,请确保它与NPM兼容。 我不知道这是否重要,但是.yarnrc注册表中有两个斜杠( // )。

@ryanjaeb因此,我们的devops团队已将Nexus锁定为_only_支持LDAP Realm。 这可能是问题的核心,但是有许多我无法使用的依赖yarn工具,因为这似乎不受支持。 我尝试将_auth附加为适当语法中的参数,等等。 似乎没有任何作用。 (FWIW:多个斜杠是相关问题的应有解决方案,无论是否成功,我都做到了。)

可以确认Nexus的Yarn身份验证已损坏。 yarn login不会提示您输入密码,但会说它已成功登录(没有-对rc文件没有更改),

发布确实会提示输入密码并发布,但无论设置为每次登录都必须从__auth令牌中读取,都不会读取。 而且您也不能在CI场景中使用yarn。

纱在CI中不起作用。 这会有用吗?

这个问题应该已经通过https://github.com/yarnpkg/yarn/pull/5216解决。 该公关的描述包含以下内容:

Fixes #4157, #4451, #4672, #4119.

这导致GitHub在合并该PR时仅自动关闭#4157。 其他问题也应该已经解决。

@valscion,这可能会进一步帮助解决这些问题//github.com/yarnpkg/yarn/pull/5322 ,但它从裂缝中溜了出来。

添加另一个数据点-yarn 1.8.x +在我的构建代理(VSTS)上失败。 仅将yarn还原为1.7.x可解决此问题。 它正在查看正确的注册表,但未使用构建代理注入到.npmrc的令牌。 我确实意识到这里有很多变量,但认为它可能有用。

在本地运行1.9.x,将令牌保存在我的用户.npmrc ,可以正常工作。

1.9.x版本

2018-08-03T21:17:04.9324575Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\Builds\_tool\yarn\1.9.4\x64\yarn-v1.9.4\bin\yarn.cmd build"
2018-08-03T21:17:05.4481355Z yarn run v1.9.4
2018-08-03T21:17:05.5418442Z $ lerna clean && lerna bootstrap
2018-08-03T21:17:08.3387809Z lerna info version 2.11.0
2018-08-03T21:17:08.3387809Z lerna info versioning independent
2018-08-03T21:17:08.3856545Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.3856545Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.3856545Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.3856545Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.4012821Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.4012821Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.4169058Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.4325326Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.4325326Z lerna info clean removing <REMOVED>
2018-08-03T21:17:08.7606628Z lerna success clean finished
2018-08-03T21:17:09.5145894Z lerna info version 2.11.0
2018-08-03T21:17:09.5145894Z lerna info versioning independent
2018-08-03T21:17:09.5419287Z lerna info Bootstrapping 9 packages
2018-08-03T21:17:09.5419287Z lerna info lifecycle preinstall
2018-08-03T21:17:09.5576221Z lerna info Installing external dependencies
2018-08-03T21:17:12.8857424Z lerna ERR! execute callback with error
2018-08-03T21:17:12.8857424Z lerna ERR! Error: Command failed: yarn install --mutex network:42424 --non-interactive
2018-08-03T21:17:12.8857424Z lerna ERR! warning package.json: No license field
2018-08-03T21:17:12.8857424Z lerna ERR! warning Waiting for the other yarn instance to finish (4048)
2018-08-03T21:17:12.8857424Z lerna ERR! warning Waiting for the other yarn instance to finish (6896)
2018-08-03T21:17:12.8857424Z lerna ERR! warning No license field
2018-08-03T21:17:12.8857424Z lerna ERR! error An unexpected error occurred: "<INTERNAL_REGISTRY>/lodash.foreach/-/lodash.foreach-2.3.0.tgz: Request failed \"401 Unauthorized\"".
2018-08-03T21:17:12.8857424Z lerna ERR! [1/4] Resolving packages...
2018-08-03T21:17:12.8857424Z lerna ERR! [2/4] Fetching packages...
2018-08-03T21:17:12.8857424Z lerna ERR! info If you think this is a bug, please open a bug report with the information provided in "C:\\Builds\\6\\s\\packages\\<REMOVED>\\yarn-error.log".
2018-08-03T21:17:12.8857424Z lerna ERR! info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2018-08-03T21:17:12.8857424Z lerna ERR! 
2018-08-03T21:17:12.8857424Z lerna ERR!     at Promise.all.then.arr (C:\Builds\6\s\node_modules\lerna\node_modules\execa\index.js:236:11)
2018-08-03T21:17:12.8857424Z lerna ERR!     at <anonymous>
2018-08-03T21:17:12.9482437Z lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
2018-08-03T21:17:13.0732458Z { Error: Command failed: yarn install --mutex network:42424 --non-interactive
2018-08-03T21:17:13.0732458Z warning package.json: No license field
2018-08-03T21:17:13.0732458Z warning Waiting for the other yarn instance to finish (4048)
2018-08-03T21:17:13.0732458Z warning Waiting for the other yarn instance to finish (6896)
2018-08-03T21:17:13.0732458Z warning No license field
2018-08-03T21:17:13.0732458Z error An unexpected error occurred: "<INTERNAL_REGISTRY>/lodash.foreach/-/lodash.foreach-2.3.0.tgz: Request failed \"401 Unauthorized\"".
2018-08-03T21:17:13.0732458Z [1/4] Resolving packages...
2018-08-03T21:17:13.0732458Z [2/4] Fetching packages...
2018-08-03T21:17:13.0732458Z info If you think this is a bug, please open a bug report with the information provided in "C:\\Builds\\6\\s\\packages\\<REMOVED>\\yarn-error.log".
2018-08-03T21:17:13.0732458Z info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2018-08-03T21:17:13.0732458Z 
2018-08-03T21:17:13.0732458Z     at Promise.all.then.arr (C:\Builds\6\s\node_modules\lerna\node_modules\execa\index.js:236:11)
2018-08-03T21:17:13.0732458Z     at <anonymous>
2018-08-03T21:17:13.0732458Z     at process._tickCallback (internal/process/next_tick.js:188:7)
2018-08-03T21:17:13.0732458Z   code: 1,
2018-08-03T21:17:13.0732458Z   killed: false,
2018-08-03T21:17:13.0732458Z   stdout: '[1/4] Resolving packages...\n[2/4] Fetching packages...\ninfo If you think this is a bug, please open a bug report with the information provided in "C:\\\\Builds\\\\6\\\\s\\\\packages\\\\<REMOVED>\\\\yarn-error.log".\ninfo Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.\n',
2018-08-03T21:17:13.0732458Z   stderr: 'warning package.json: No license field\nwarning Waiting for the other yarn instance to finish (4048)\nwarning Waiting for the other yarn instance to finish (6896)\nwarning No license field\nerror An unexpected error occurred: "<INTERNAL_REGISTRY>/lodash.foreach/-/lodash.foreach-2.3.0.tgz: Request failed \\"401 Unauthorized\\"".\n',
2018-08-03T21:17:13.0732458Z   failed: true,
2018-08-03T21:17:13.0732458Z   signal: null,
2018-08-03T21:17:13.0732458Z   cmd: 'yarn install --mutex network:42424 --non-interactive',
2018-08-03T21:17:13.0732458Z   timedOut: false,
2018-08-03T21:17:13.0732458Z   exitCode: 1 }
2018-08-03T21:17:13.0888721Z error Command failed with exit code 1.
2018-08-03T21:17:13.0888721Z info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

1.7.X版本

2018-08-03T21:33:16.4477199Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\Builds\_tool\yarn\1.7.0\x64\yarn-v1.7.0\bin\yarn.cmd build"
2018-08-03T21:33:16.9633413Z yarn run v1.7.0
2018-08-03T21:33:17.0727225Z $ lerna clean && lerna bootstrap
2018-08-03T21:33:19.2509802Z lerna info version 2.11.0
2018-08-03T21:33:19.2509802Z lerna info versioning independent
2018-08-03T21:33:19.2666043Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.2666043Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.2666043Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.2666043Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.2978554Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.5478528Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.5478528Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.5478528Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.6728520Z lerna info clean removing <REMOVED>
2018-08-03T21:33:19.8759839Z lerna success clean finished
2018-08-03T21:33:20.5947225Z lerna info version 2.11.0
2018-08-03T21:33:20.5947225Z lerna info versioning independent
2018-08-03T21:33:20.6103497Z lerna info Bootstrapping 9 packages
2018-08-03T21:33:20.6103497Z lerna info lifecycle preinstall
2018-08-03T21:33:20.6415982Z lerna info Installing external dependencies
2018-08-03T21:33:23.1103303Z lerna info Symlinking packages and binaries
2018-08-03T21:33:23.1415791Z lerna info lifecycle postinstall
2018-08-03T21:33:23.1415791Z lerna info lifecycle prepublish
2018-08-03T21:33:23.1415791Z lerna info lifecycle prepare
2018-08-03T21:33:23.1415791Z lerna success Bootstrapped 9 packages
2018-08-03T21:33:23.1572133Z $ ts-node ./build/index.ts
2018-08-03T21:33:58.5218101Z Done in 41.54s.

大家好,我要求其他人关注此问题并使用私有注册表。

我们正在考虑从锁定文件中删除注册表主机名。 这将使从私有注册表切换到另一个注册表更加容易,但是缺点是所有注册表都需要使用相似的URL(由于主机名不是URL的一部分,因此我们只能在运行时将其与活动注册表合并组态)。

您能否帮助我们在#5892中确认此工作流程将对您的私人注册表提供者起作用(或告诉我们是否可行)? 这将帮助我们获得进行此更改所需的置信度。 谢谢!

我遇到了yarn publish无法从我的.npmrc读取身份验证令牌的问题。 我在Ubuntu上运行它。

版本号

纱-1.9.4
npm-5.5.1

〜/ .npmrc

这是我的~/.npmrc样子(混淆了令牌和注册表):

registry=http://myprivateregistry.net/
//myprivateregistry.net/:_authToken="myAuthToken"

输出量

运行yarn publish --noninteractive ,出现以下错误:

yarn publish v1.9.4
[1/4] Bumping version...
info Current version: 2.1.3
[2/4] Logging in...
error No token found and can't prompt for login when running with --non-interactive.
info Visit https://yarnpkg.com/en/docs/cli/publish for documentation about this command.

调试步骤

我尝试了以下无济于事:

  • ~/.npmrc复制到我的项目目录中的本地.npmrc
  • 使用我的凭据运行yarn login ,然后再运行yarn publish

我还验证了运行npm publish可以通过身份验证步骤(在版本控制步骤中失败,因为它不会让我覆盖相同的版本号。这就是为什么我要使用yarn publish --non-interactive ,因为它允许上传具有相同版本号的README更改)

还有其他我想念的东西吗? 谢谢!

@ liuhelen10您的项目中有.yarnrc文件吗? 这对我有用,令牌存储在~/.npmrc

$ cat .yarnrc 
registry "https://registry.npmjs.org/"

.npmrc中的always-auth = true做到了这一点,在使用Yarn时不再接收401。
这没有意义,但无论如何:)

此问题已在2017年报告,现在是2019年,此问题仍然存在。

同意,这仍然行不通。

.npmrc

always-auth=true
<strong i="7">@somename</strong>:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=[token]

.yarnc

"<strong i="11">@somename</strong>:registry" "https://npm.pkg.github.com/"

我在npm.pkg.github.com上也遇到了错误:

Integrity checked failed (none of the specified algorithms are supported

我在npm.pkg.github.com上也遇到了错误:

Integrity checked failed (none of the specified algorithms are supported

也得到这个

我在使用Nexus 3时遇到了同样的问题,但是使用@plitex在本期https://github.com/yarnpkg/yarn/issues/3093#issuecomment -317671597中提到的方法解决了。

将此内容放在.npmrc文件中。 您不需要在.yarnrc文件中进行任何设置。

always-auth=true
registry=https://nexus.server.com/repository/npm-group/
//nexus.server.com/repository/npm-group/:_authToken={AUTH_TOKEN}

纱线-版本
1.17.3

npm --version
6.10.2

@nbransby@revmischa :还请检查问题#7552,这可能是此实例中的错误消息是正确的。

有两件事帮助我:

  1. always-auth = true
  2. rm yarn.lock

我在纱线1.19.1上开始出现此错误。 在那条纱线似乎可以从.npmrc正确地获取注册表和令牌信息之前,但是对于1.19.1,我还必须在.yarnrc添加registry配置,否则我刚收到401错误。

一旦完成,它就起作用了,并继续从.npmrc领取令牌。 在我看来,这似乎是一种回归-似乎没有任何充分的理由将注册表配置从.npmrc复制到.yarnrc

就像@rocketraman一样,一旦我安装yarn 1.19.1,尝试从私有注册表(nexus)安装作用域包时,我就开始经历401s了。 npm install工作正常。

纱线降级后所有工作再次进行:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.17.3

可以确认这还是一个问题

运行yarn install时出现401错误

Request "https://npm.pkg.github.com/user/@scope/package" finished with status code 401.

其中npn install以零发行运行

我花了最后2个小时来调试此问题,感谢我的朋友@AndreiCalazans ,我有一个解决方法。

在这里分享给任何可能在相似领域挣扎的人。

用例

我正在将一个使用yarn工作区的项目部署到Heroku。 即使我放下yarn.lock并使用npm install ,该项目也是使用工作空间构建的,如果没有yarn ,_根本无法工作。

该项目依赖于托管在GitHub Packages上的软件包,并且需要通过令牌针对GitHub进行身份验证。

问题

Heroku将看到yarn.lock并使用yarn安装依赖项,这将忽略我创建的预构建的~/.npmrc文件。

预构建,我会运行

echo "always-auth=true\n//npm.pkg.github.com/:_authToken=${GITHUB_NPM_TOKEN}\" >> ~/.npmrc",

这将创建一个文件~/.npmrc ,其内容如下:

always-auth=true
//npm.pkg.github.com/:_authToken=whatevermytokenis

当尝试使用401 Unauthorized从GitHub包注册表中提取依赖项时, yarn会完全忽略此问题并失败。

解决方法

安德烈(Andrei)提到了_just org_以使用GitHub注册表别名,然后_then_在其下添加GitHub注册表令牌。

本质上,稍微更改~/.npmrc文件以添加以下内容:

always-auth=true
+<strong i="36">@MY_ORG</strong>:registry=https://npm.pkg.github.com/

//npm.pkg.github.com/:_authToken=whatevermytokenis

这解决了所有问题,突然之间, yarn使用提供的身份验证令牌以npm.pkg.github.com购买了GitHub组织中@MY_ORG以下的任何软件包。

ew! 我希望这可以帮助别人! 💞

这仍然是一个问题! NPM安装运行没有问题,纱线添加
error Couldn't find package "@diligentcorp/atlas-react" on the "npm" registry. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

在我的Windows计算机上,问题是用户级别为.npmrc文件的用户文件夹位于网络驱动器上。 机器上的本地用户文件夹没有.npmrc文件,但是似乎在该文件夹中查找yarn。 将.npmrc从网络驱动器复制到本地用户文件夹解决了该问题(身份验证令牌存储在用户级别.npmrc中)。

我在git bash中键入“ cd〜”后发现是偶然的,并且将其切换到远程主文件夹(我从未使用过)。

@TejasQ解决方法对我不起作用。

我也在使用GitHub软件包。
即使与npm完美搭配仍能获得401 unauthorized npm

我设法使其与纱线v1.22.0一起使用

.npmrc

always-auth=true
<strong i="7">@fortawesome</strong>:registry=https://npm.fontawesome.com
//npm.fontawesome.com/:_authToken=xyz-xyz-xyz-xyz

.yarnrc

"<strong i="11">@fortawesome</strong>:registry" "https://npm.fontawesome.com"

registry "https://some-regular-registry.org"

然后执行: yarn add @fortawesome/fontawesome-pro

我也很高兴,我希望我只用.npmrc就可以使用它,但是它只在添加.yarnrc时才起作用,所以我们只需要复制yarn的配置即可。

我认为这就是我遇到的问题。 当.npmrc在主目录中但不在项目目录中时(jenkins / travis所需),它可以工作。
https://github.com/yarnpkg/yarn/issues/8034

这为我解决了问题: https :

设置范围一时,请确保注册表后没有/name

- <strong i="7">@4r7d3c0</strong>:registry=https://npm.pkg.github.com/4r7d3c0
+ <strong i="8">@4r7d3c0</strong>:registry=https://npm.pkg.github.com

根据文档registry=https://npm.pkg.github.com/OWNER ,我忽略了设置范围时所有者不需要在那里。 NPM可以处理它,但是毛线不能。

对于那些使用别名的人,请检查以下解决方法: https :

必须拆分用户级别的.npmrc和项目级别的.npmrc以使yarn尊重GitHub软件包令牌。 将命名注册表声明从用户级别移至项目级别是关键

~/.npmrc

_auth=#####TOKEN_FOR_ARTIFACTORY#####
always-auth=true
registry=https://artifactory.mycompany.net/artifactory/api/npm/npm/
//npm.pkg.github.com/:_authToken=####GitHub_NPM_REGISTRY_TOKEN#####

~/projects/blah/.npmrc

<strong i="14">@mycompany</strong>:registry=https://npm.pkg.github.com

直到我将名为^的家庭软件包注册表项移动到项目级别.npmrcyarn install给了我401(对于@mycompany下的GH托管软件包)。

对于Docker构建,请分别安装它们:

base.Dockerfile

# syntax=docker/dockerfile:1-experimental
## ^ need to enable --mount=type=secret support

ARG BASE_IMAGE
FROM ${BASE_IMAGE} as build

# note that only project-level .npmrc is copied
COPY package.json yarn.lock .npmrc ./

# ~/.npmrc with actual secrets is mounted as "secret" (does not stay in image)
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required \
    yarn install --production --frozen-lockfile ...

Docker构建命令:

DOCKER_BUILDKIT=1 docker build \
        --build-arg BASE_IMAGE=$(BASE_IMAGE) \
        --secret id=npmrc,src="$(HOME)/.npmrc" \
        -t $(IMAGE_NAME):$(IMAGE_TAG) \
        -f base.Dockerfile .

_(注意,我不需要.yarnrc来工作,但是我使用的是1.17.3纱线,因此其他版本可能有所不同)_

我已经进行了一些挖掘,似乎yarn使用了错误的身份验证凭据。

〜/ .npmrc

//npm-old.visualon.de/npm/vo-npm/:_password=XXXXXX
//npm-old.visualon.de/npm/vo-npm/:username=kriese
//npm-old.visualon.de/npm/vo-npm/:always-auth=true

//npm-new.visualon.de/:_authToken="XXXXXX"

package.json

{
  "name": "yarn-auth",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "tslib": "^2.0.1",
    "moment": "2.20.1"
  }
}

纱锁

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


[email protected]:
  version "2.20.1"
  resolved "https://npm-old.visualon.de/npm/vo-npm/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"
  integrity sha1-1usaRsvMFKKy+UNBEsH/iQfzE/0=

tslib@^2.0.1:
  version "2.0.1"
  resolved "https://npm-new.visualon.de/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e"
  integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==

在尝试安装yarn时,会将bearer令牌从npm-new.visualon.de发送到npm-old.visualon.de 。 因此,它仅捕获纱线与基本域进行比较。

如果仍然有人面对它,这就是对我有用的方法。

.npmrc:
always-auth=true
<strong i="6">@orgaccount</strong>:registry=https://npm.pkg.github.com
registry=https://registry.yarnpkg.com

https://npm.pkg.github.com/:_authToken=yyyyjjjjj3333888etc

不知道是否有人遇到类似的问题,但这也许可以帮助某人节省一些时间:

我使用Azure Artifacts作为私有注册表,并按照此处记录的那样设置了PAT和.npmrc文件。
但是,我遇到了一个同样的问题,即npm install正常工作,但是yarn install遇到401错误。
经过一番尝试和错误事实证明,我的注册表URL中有一个特殊字符(... @ Local / ...),但是Azure Artifacts将其解析为安装指南中的Unicode表示形式。 npm处理得很好,纱线不是很多。 在URL中设置实际的@字符可以解决我的问题。

此页面是否有帮助?
0 / 5 - 0 等级