标题有点啰嗦。 换句话说:当.npmrc
(或者,大概是.yarnrc
)配置了_both_一个私有注册表 URL _and_一个用于发布到公共 npm 的身份验证令牌时,安装范围包会中断。 这里有问题的私有注册表是 Artifactory,目前的理论是 Yarn 正在发送凭证(_不恰当地_:配置用于两个不同的 URL),Artifactory 对此不满意,以及 401(因为凭证用于公共 npm,不是人造的)。 我不确定为什么范围包会被区别对待,否则它可以正常工作。
下面是一些命令来说明:
> pwd
~
> cat .yarnrc
cat: .yarnrc: No such file or directory
> cat .npmrc
registry=<private registry URL that works fine with npm and non-scoped packages>
//registry.npmjs.org/:_authToken=<my auth token>
> yarn add @types/d3-scale --verbose
yarn add v0.19.1
info No lockfile found.
verbose Performing "GET" request to "https://yarnpkg.com/latest-version".
[1/4] 🔍 Resolving packages...
verbose Performing "GET" request to "<correct private registry URL ...>/@types%2fd3-scale".
verbose Request "<correct private registry URL ...>/@types%2fd3-scale" finished with status code 401.
verbose Error: Couldn't find package "@types/d3-scale" on the "npm" registry.
at MessageError (/usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/lib/errors.js:8:5)
at /usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/lib/resolvers/registries/npm-resolver.js:207:15
at next (native)
at step (/usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at process._tickCallback (internal/process/next_tick.js:103:7)
error Couldn't find package "@types/d3-scale" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
> npm install @types/d3-scale
~
└─┬ @types/[email protected]
└── @types/[email protected]
> yarn add d3-scale
yarn add v0.19.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 8 new dependencies.
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
✨ Done in 2.45s.
# edit .npmrc...
> cat .npmrc
registry=<same registry URL>
> yarn add @types/d3-scale
yarn add v0.19.1
warning No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ @types/[email protected]
└─ @types/[email protected]
warning No license field
✨ Done in 1.50s.
对于额外的背景,Artifactory 实例被配置为允许匿名访问。 如果您不提供凭据,则可以阅读任何您喜欢的内容。 如果您提供任何凭据,Artifactory 会尝试验证它们并返回 401 状态(在这种情况下,因为用户不存在。)
我认为这是有问题的代码行: https :
在上下文中阅读似乎作者假设“范围”意味着“经过身份验证”。
上周五遇到了完全相同的问题,必须从 ~/.npmrc 中删除身份验证令牌才能从本地工件下载范围包。
最有用的评论
我认为这是有问题的代码行: https :
在上下文中阅读似乎作者假设“范围”意味着“经过身份验证”。