npm - Artifactory:在 'npmjs' 处找不到 npm 存储库索引

标签 npm artifactory

我正在使用 Artifactory Pro 4.12.1。我创建了一个名为 npmjs-local 的本地 npm 存储库、一个名为 npmjs-remote 的远程 npm 存储库和一个名为 npmjs 的虚拟 npm 存储库,聚合前两个存储库。

然后我将 npm 配置为使用 Artifactory 作为注册表,使用:

$ npm config set registry http://artifactory.example.org/artifactory/api/npm/npmjs

当我尝试使用 npm search foo 搜索包时,出现以下错误:

npm WARN Building the local index for the first time, please be patient
npm ERR! registry error parsing json
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/7.2.0/bin/node" "/usr/local/bin/npm" "search" "foo"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9

npm ERR! Unexpected token C in JSON at position 0
npm ERR! Cannot find the npm repository index at 'npmjs'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dserodio/npm-debug.log

我使用 --loglevel verbose 运行了相同的搜索,我看到“无效的 JSON”来自 http://artifactory.example.org/artifactory/api/npm/npmjs/-/all :

Cannot find the npm repository index at 'npmjs'

编辑:这既通过 Nginx 代理又直接通过 Artifactory 发生。这是完整的 HTTP 响应:

$ curl -v http://artifactory.example.org:8081/artifactory/api/npm/npmjs/-/all
*   Trying 10.1.2.3...
* Connected to artifactory.example.org (10.1.2.3) port 8081 (#0)
> GET /artifactory/api/npm/npmjs/-/all HTTP/1.1
> Host: artifactory.example.org:8081
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: Artifactory/4.12.1
< X-Artifactory-Id: b0f4dd7e3f5106cd:-3efe7253:158c0a36030:-7ffd
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Tue, 06 Dec 2016 16:35:01 GMT
<
* Connection #0 to host artifactory.example.org left intact
Cannot find the npm repository index at 'npmjs'

什么可能导致此错误?

最佳答案

如果从未生成虚拟存储库的 NPM 索引,则可能会发生这种情况。

解决该问题的最佳方法是重新索引存储库,这可以使用 REST API 来完成:

curl -uadmin:password -XPOST http://artifactory.example.org:8081/artifactory/api/npm/npmjs/reindex

REST 调用将触发异步索引过程,可以使用 Artifactory 日志文件对其进行监控。您应该看到如下消息:

2016-12-07 13:11:02,455 [http-nio-8081-exec-5] [INFO ] (o.a.a.n.r.NpmRequestHelper:124) - Recalculating index for npm repository npmjs scheduled to run
2016-12-07 13:12:02,527 [art-exec-102209] [INFO ] (o.a.a.n.NpmServiceImpl:237) - Npm metadata recalculation has been started for repository 'npmjs'
2016-12-07 13:13:31,071 [art-exec-102209] [INFO ] (o.a.a.n.NpmServiceImpl:263) - Finished npm metadata recalculation for repo 'npmjs' in 1.48 minutes

关于npm - Artifactory:在 'npmjs' 处找不到 npm 存储库索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40997150/

相关文章:

javascript - `npm audit` 不断返回 "Your configured registry (https://registry.npmjs.org/) does not support audit requests."。我如何让它再次工作?

gradle - 更新build.gradle以构建一个jar文件并将其推送到 Artifactory

json - 人工 REST API : How to generate Build Info json

java - JFrog Artifactory 和 Oracle 存储库

docker - 无法在禁用匿名访问的情况下推送到Artifactory中的Docker注册表

node.js - npm install 上缺少目录和文件

node.js - 将 Node.js 应用程序推送到 Heroku 时跳过 "Installing dependencies with npm"步骤

css - 标准化 SVG 图标和网络字体

node.js - 使用 yeoman 生成角度应用程序时出错 : unhandled Template render error

Artifactory 和 Gradle : Running license checks