为什么 npm 说 404 而 curl 可以 200

Why is npm saying 404 when curl can 200

我在 .npmrc 文件中添加了 myscope:registry=https://myprivatedomain.com/artifactory/api/npm/npm-myregistry-release/ 这样的注册表。

当我执行 npm install @myscope/mypackage 时,它显示 404 Not Found。当我 cat 调试日志时它有错误 7 http fetch GET 404 https://myprivatedomain.com/artifactory/api/npm/npm-myregistry-release/@myscope%2fmypackage 1463ms 这很奇怪,因为如果我这样做 curl https://myprivateregistry.com/@myscope%2fmypackage 我会看到一个响应。知道我可能配置错了什么吗?

在 curl 上使用 -i 给我所有你期望的合适的东西,比如 200:

HTTP/1.1 200 OK
Date: Fri, 20 Jul 2018 19:03:17 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: Artifactory/5.10.3
X-Artifactory-Id: 3cfb3447e11ab4943a37f53d7a5dcd357274261d
X-Artifactory-Node-Id: art2
ETag: c3636860e64da7eda14f65ff25c1e8ad11266adc

我做了 npm search @myscope 但一无所获。然后我将 .npmrc 更新为 registry=https://myprivatedomain.com/artifactory/api/npm/npm-myregistry-release/ 和 运行 搜索。我看到包裹上来了。尽管现在搜索工作正常,但当我去安装时它仍然说 404。

我让我的同事使用相同的 npm 配置,这对他很有效。我关闭了我的终端并重新启动(以防我使用 npm login 以某种方式设置了一些糟糕的东西,作为完整性检查)但问题仍然存在。如果我执行 npm logout 并尝试安装,我会收到 401。然后我再次执行 npm login 并返回到 E404

我也进入我的 .gitconfig 并注释掉 insteadOf 像这样:

#[url "https://"]
#       insteadOf = git://

老实说,我不确定为什么会出现这种情况,但似乎值得尝试为此发表评论。

根据official Artifactory documentation,正确的URL应该是:

npm config set registry http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/npm-repo/

对于您的情况:myprivateregistry.com/api/npm/npm-repo:与您的同事(没有问题)核实 his/her .npmrc 参考文献。

从 OP 来看,注册表端的工件存在缺陷。
对它 影响另一位同事的一种解释是说同事在 his/her 本地 npm 缓存中有它。

注册表端似乎存在一些配置问题。将其写为占位符。希望让注册表所有者写下他们为纠正此问题所做的工作。非常奇怪,因为它并没有影响到每个人。