简体   繁体   English

如何在 GitLab NPM Registry 中发布我的 npm 包?

[英]How to publish my npm package in GitLab NPM Registry?

I hooked up a trial gold plan to test GitLab NPM Registry functionality.我制定了一个试用黄金计划来测试 GitLab NPM Registry 功能。

  1. Created a gitlab prohect with the name "bar".创建了一个名为“bar”的 gitlab prohect。
  2. Created a file to generate a token: in the file with the name auth.txt I wrote the line: grant_type=password&username=my-gitlab-username& password=my-gitlab-password创建了一个文件来生成一个令牌:在名为 auth.txt 的文件中我写了一行: grant_type=password&username=my-gitlab-username& password=my-gitlab-password

  3. Generated a token using the command: curl -d "@ auth.txt" -X POST http:/gitlab.com/oauth/token使用命令生成令牌: curl -d "@ auth.txt" -X POST http:/gitlab.com/oauth/token

  4. In the .npmrc file, the path was indicated gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/:_ authToken=my-genereated-token在 .npmrc 文件中,路径表示为gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/:_ authToken=my-genereated-token
  5. Created an app.js file for testing, with the contents: console.log('test')创建了一个用于测试的 app.js 文件,内容为: console.log('test')
  6. Created a json package with content创建了一个包含内容的 json 包
    {
      "name": "@foo/bar",
      "version": "1.0.0",
      "description": "",
      "main": "app.js",
      "dependencies": {
        "express": "^4.16.4"
      },
      "devDependencies": {},
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node app.js"
      },
      "author": "",
      "license": "ISC",
      "publishConfig": {
        "registry":"http://gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/"
      }
    }

6.In the folder now there are 3 files: 6.文件夹里现在有3个文件:

    .npmrc
    app.js
    package.json
  1. I start publishing the package to the repository with the command我开始使用命令将包发布到存储库

npm --verbose publish

  1. It is not published!它没有发布! writes:写道:
    npm verb cli [ '/usr/bin/node', '/usr/local/bin/npm', '--verbose', 'publish' ]
    npm info using npm@6.14.2
    npm info using node@v13.11.0
    npm verb npm-session febf284b8dfbe40b
    npm verb publish [ '.' ]
    npm info lifecycle @foo/bar@1.0.0~prepublish: @foo/bar@1.0.0
    npm info lifecycle @foo/bar@1.0.0~prepare: @foo/bar@1.0.0
    npm info lifecycle @foo/bar@1.0.0~prepublishOnly: @foo/bar@1.0.0
    npm info lifecycle @foo/bar@1.0.0~prepack: @foo/bar@1.0.0
    npm info lifecycle @foo/bar@1.0.0~postpack: @foo/bar@1.0.0
    npm notice
    npm notice 📦  @foo/bar@1.0.0
    npm notice === Tarball Contents ===
    npm notice 687B logs
    npm notice 175B app.js
    npm notice 404B package.json
    npm notice 582B README.md
    npm notice 55B  auth.loc.txt
    npm notice 59B  auth.txt
    npm notice === Tarball Details ===
    npm notice name:          @foo/bar
    npm notice version:       1.0.0
    npm notice package size:  1.1 kB
    npm notice unpacked size: 2.0 kB
    npm notice shasum:        c4220955014b80c6948ff2a20124ac8d145d0675
    npm notice integrity:     sha512-pOQJVaXuneH80[...]DdtCjSLD1vkDQ==
    npm notice total files:   6
    npm notice 
    npm http fetch PUT 301 http://gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/@foo%2fbar 283ms
    npm info lifecycle @foo/bar@1.0.0~publish: @foo/bar@1.0.0
    npm info lifecycle @foo/bar@1.0.0~postpublish: @foo/bar@1.0.0
    @foo/bar@1.0.0
    npm verb exit [ 0, true ]
    npm timing npm Completed in 555ms
    npm info ok
  1. But in the GitLab in the list on the left - in Packages > List not a single package is displayed, either in the All section or in the NPM section.但是在左侧列表的 GitLab 中 - 在Packages > List ,无论是在 All 部分还是在 NPM 部分,都没有显示单个包。

Please help me figure out what I'm doing wrong.请帮我弄清楚我做错了什么。

You can try to specify the package registry for the exact project.您可以尝试为确切的项目指定包注册表。

.npmrc file example: .npmrc 文件示例:

# Set URL for your scoped packages.
@foo:registry=https://gitlab.com/api/v4/projects/<Source Project ID>/packages/npm/

# Add the token for the scoped packages URL. This will allow you to download
//gitlab.com/api/v4/projects/<Source Project ID>/packages/npm/:_authToken=${CI_JOB_TOKEN}

# with the project you want your package to be uploaded to.
//gitlab.com/api/v4/projects/<Destination Project ID>/packages/npm/:_authToken=${CI_JOB_TOKEN}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 NPM package 发布到 NPM 注册表而不是 github 注册表? - How to publish NPM package to NPM registry instead of github registry? npm 发布失败 GitLab NPM 注册表 - npm publish fails with GitLab NPM registry 如何将 npm package 依赖项部署到 gitlab 注册表? - How to deploy npm package dependencies to gitlab registry? 获取 npm 错误 npm ERR! 尝试将新的 npm 包版本发布到 npm 时,404 &#39;@my-package@2.0.0&#39; 不在此注册表中 - Get npm error npm ERR! 404 '@my-package@2.0.0' is not in this registry when try to publish new npm package version to npm Gitlab - npm 注册表 - npm 发布 - 422 不可处理的实体 - Gitlab - npm registry - npm publish - 422 Unprocessable Entity 如何使用 gitlab ci 发布私有 npm 包? - How do I publish a private npm package with gitlab ci? 使用标签将 npm 包发布到 Gemfury 注册表? - Publish npm package to a Gemfury registry with tag? 无法从 GitHub 操作发布到 npm:`<package> 不在 npm 注册表中的错误 - Cannot publish to npm from GitHub Actions: `<package> is not in the npm registry` error 如何从 npm 注册表中删除 npm 包? - How to delete an npm package from the npm registry? 如何使用身份验证令牌将范围 npm package 发布到私有 Bytesafe npm 注册表 - How to publish a scoped npm package to a private Bytesafe npm registry using an Auth Token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM