'Gitlab package registry throw 404 on npm publish

I'm trying to publish a package to Gitlab package registry but it keeps erroring me with 404 @my-scope/<package-name> is not in this registry.

Initially I followed the instructions in here official docs

This is how my .npmrc looks like:

@my-scope:registry=https://gitlab.com/api/v4/projects/<project_id>/packages/npm/
//gitlab.com/api/v4/projects/<project_id>/packages/npm/:_authToken=${TOKEN}

also I've added publishConfig to package.json

  "publishConfig": {
    "@my-scope:registry": "https://gitlab.com/api/v4/projects/<project_id>/packages/npm/"
  },

When I run npm publish I keep getting 404 error as below.

npm notice Publishing to https://gitlab.com/api/v4/projects/<project_id>/packages/npm/
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://gitlab.com/api/v4/projects/<project_id>/packages/npm/@my-scope%2fpackage-name
npm ERR! 404 
npm ERR! 404  '@my-scope/[email protected]' is not in this 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


Solution 1:[1]

Your .npmrc should looks like this according to the docs:

@foo:registry=https://gitlab.example.com/api/v4/packages/npm/
//gitlab.example.com/api/v4/packages/npm/:_authToken=${MY_TOKEN}
//gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=${MY_TOKEN}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Minaro