【问题标题】:GitLab '404 Not Found' error when publishing a package using NPM使用 NPM 发布包时出现 GitLab '404 Not Found' 错误
【发布时间】:2021-11-07 06:11:45
【问题描述】:

我在尝试使用 NPM 和 GitLab 的“实例级”范围/命名空间配置 (reference) 将包发布到 GitLab 的私有/自托管实例的包存储库时遇到404 Not Found 错误。

错误

执行$ TOKEN=<ACCESS_TOKEN> npm publish会导致以下错误:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://gitlab.example.com/api/v4/packages/npm/@org%2fpackage-1 - 404 Not Found
npm ERR! 404 
npm ERR! 404  '@org/package-1@0.1.0' 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配置如下:

package.json

{
  "name": "@org/package-1",
  "version": "0.1.0",
  "private": false,
  "peerDependencies": {
  },
  "dependencies": {
  }
}

~/.npmrc

@org:registry=https://gitlab.example.com/api/v4/packages/npm/
//gitlab.example.com/api/v4/packages/npm/:_authToken=$TOKEN

# @org/package-1
//gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/npm/:_authToken=$TOKEN

# @org/package-2
//gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/npm/:_authToken=$TOKEN

# @org/package-3
//gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/npm/:_authToken=$TOKEN

【问题讨论】:

    标签: node.js npm gitlab


    【解决方案1】:

    解决方案

    publishConfig 添加到 package.json 以及与代码存储库关联的 GitLab 包存储库的 URL。

    package.json(部分)

    "publishConfig": {
        "@org:registry": "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/npm/"
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-05
      • 2016-01-25
      • 2017-09-03
      • 2012-09-27
      • 2021-07-20
      • 1970-01-01
      • 2021-12-23
      • 2017-11-25
      相关资源
      最近更新 更多