Can't publish private npm package on Gitlab - E404 Not found PUT
Asked Answered
E

2

12

I've tried many different docs and tutorials to publish a scoped npm package on a private gitlab instance.

So far I've:

Created a deploy token with package write & read permissions: token

Setup a .npmrc file with the following contents:

@<scope>:registry=https://<domain>/api/v4/packages/npm/

//<domain>/api/v4/projects/<id>/packages/npm/:_authToken=<token>

//<domain>/api/v4/packages/npm/:_authToken=<token>

Added "publishConfig" to "package.json":

{
  "name": "@<scope>/<name>",
  "version": "1.0.0",
  "main": "dist/index.js",
  "license": "MIT",
  "publishConfig": {
    "@<scope>:registry": "https://<domain>/api/v4/projects/<id>/packages/npm"
  },
  "scripts": {
    "build": "tsc",
    "prepublish": "tsc"
  },
  "devDependencies": {
    "ts-node": "^9.1.1"
  }
}

Verified that the repo allows packages to be stored:

package permission

But everytime I try and run either npm publish or yarn publish, it builds, packages but fails to publish:

error

The log file verbosily repeats the error log above.

I'm trying to release a private SDK for an internal service and would need a way to publish it so only those with the correct credentials can install it on their projects.

The link provided (Not Found - PUT https:// <link...> ) redirects to npmjs.com, which I believe wasn't supposed to happen, since I'm trying to store it on Gitlab instead of purchasing an organization on npmjs.

I've tried this process both on the private domain (running gitlab 13.9.1) and on https://gitlab.com, both with the same result on the same repository configuration disclosed above.

Am I missing some step? Thanks in advance!

Ethnic answered 8/3, 2021 at 19:4 Comment(0)
P
3

Your .npmrc file has both instance and project level endpoints, but if you're using a project deploy token, the authentication of the token you're providing is scoped to the project, so you should only have the project endpoint.

@<scope>:registry=https://<domain>/api/v4/projects/<ID>/packages/npm/

//<domain>/api/v4/projects/<ID>/packages/npm/:_authToken=<TOKEN>

Paramnesia answered 8/1, 2022 at 18:14 Comment(0)
C
0

The project ID in the redacted part of URL shown as part of error message resulting from attempted publish looks rather long. The project's ID isn't the project's slug. it's a numeric value instead.

Cornu answered 8/8, 2021 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.