1

I hooked up a trial gold plan to test GitLab NPM Registry functionality.

  1. Created a gitlab prohect with the name "bar".
  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

  3. Generated a token using the command: 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
  5. Created an app.js file for testing, with the contents: console.log('test')
  6. Created a json package with content
    {
      "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:

    .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.

Please help me figure out what I'm doing wrong.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
mike
  • 19
  • 2
  • 5
  • Do the published example verbatim. https://docs.gitlab.com/ee/user/packages/npm_registry/#authenticating-with-a-personal-access-token In the text you've provided, I see an inconsistency where your publishConfig just has `"registry":` but the example uses `"@foo:registry":`. And it looks like you went a little off-script, not running the `npm config set` commands shown in the guide. – ahogen Mar 27 '20 at 16:06
  • Have you foud a solution? I'm stuck with the same problem. Successful publish in logs and empty packages list as a result. – Anton Bystrov Mar 01 '21 at 07:49
  • HTTP 301 is moved permanently. try using HTTPS instead of HTTP – Thomas Mar 02 '21 at 16:55
  • Try to add this in .npmrc file: https://stackoverflow.com/a/68465417/4049017 – Karen Danielyan Jul 21 '21 at 08:30

1 Answers1

0

You can try to specify the package registry for the exact project.

.npmrc file example:

# 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}
Karen Danielyan
  • 1,560
  • 1
  • 9
  • 13