【问题标题】:Unable to install published GitLab private package无法安装已发布的 GitLab 私有包
【发布时间】:2021-08-23 12:22:00
【问题描述】:

我成功地在我组织的私有 GitLab 存储库中发布了一个包。在我的全局和本地 .npmrc 配置文件中,我有以下内容:

# Set URL for your scoped packages.
@<main-package-name>:registry=https://gitlab.<my-organisation-domain>/api/v4/packages/npm/

'//gitlab.<my-organisation-domain>/api/v4/packages/npm/:_authToken'="<my-token>"

'//gitlab.<my-organisation-domain>/api/v4/projects/<my-project-id>/packages/npm/:_authToken'="<my-token>"

package.json 文件中,我具有以下属性:

  "publishConfig": {
    "@<main-package-name>:registry": "https://gitlab.<my-organisation-domain>/api/v4/projects/<my-package-id>/packages/npm/"
  },
  "name": "@<main-package-name>/<library-name>",
  ...

在 GitLab 包和注册表项目的页面上,它显示以下内容:

安装

npm i @&lt;main-package-name&gt;/&lt;library-name&gt;

注册表设置

echo @&lt;main-package-name&gt;:registry=https://gitlab.&lt;my-organisation-domain&gt;/api/v4/packages/npm/ &gt;&gt; .npmrc

我在项目的 package.json 中添加了 "@&lt;main-package-name&gt;/&lt;library-name&gt;": "~0.0.11",但是当我尝试运行 npm install 时,我得到:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@<main-package-name>/<library-name> - Not found
npm ERR! 404 
npm ERR! 404  '@<main-package-name>/<library-name>@~0.0.11' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /path/to/log

它似乎试图从 npmjs 而不是指定的 GitLab 注册表中获取包。有人可以帮忙吗?

【问题讨论】:

    标签: npm gitlab


    【解决方案1】:

    由于一些非常奇怪的原因,在我请求包的项目中删除本地 .npmrc 并在我家中只保留全局包解决了这个问题。

    【讨论】:

      【解决方案2】:

      可能是 url 编码的问题,请检查 url 中是否没有 %2f 在您的范围和包名之间找不到

      对我来说这是我的 gitlab 虚拟主机配置的问题

      我添加了以下几行并解决了我的问题:

      AllowEncodedSlashes NoDecode

      AllowEncodedSlashes 开启

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 2021-06-06
      • 2023-02-01
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      • 1970-01-01
      • 2022-07-28
      • 1970-01-01
      相关资源
      最近更新 更多