NPM Publish returns error 400

Hello, fellow forum members!
Straight to the point…

I created a test repo to try publishing private NPM packages. I wanted to try it with Lerna first, that’s why the project name is ‘lerna-experiment’, but I am not able to get even a basic npm publish to work.

The repo setup is the most basic setup you can have. The entire repo consists of index.js, package.json, and .npmrc.

Contents of index.js:
module.exports = "test"

Contents of package.json:

  "name": "@lerna-experiment/test",
  "version": "1.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "repository": {
    "type": "git",
    "url": "git+<my_username>/lerna-experiment.git"
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "<my_username>/lerna-experiment/issues"
  "homepage": "<my_username>/lerna-experiment#readme",
  "publishConfig": {
    "@lerna-experiment:registry": "<project_id>/packages/npm/"

Contents .npmrc:


And this is what happens when I try npm publish…

npm ERR! code E400
npm ERR! 400 Bad Request - PUT<project_id>/packages/npm/@lerna-experiment%2ftest

I tried manually setting the registry URL with npm set but it had no effect. The project is not a part of any group.

What could I be doing wrong?

Thank you in advance for your answers.

Hi, a couple of quick questions:

  • is package repository enabled for your project? (Settings > General > Visibility, project features, permission)
  • if you have 2FA active, are you using a deploy token with the right scopes?
  • did you replace <project_id> with your real project id?
  • are you using Gitlab CI?

Hi! Thanks for your willingness to help.
To answer your questions…

  1. Yes, I do have enabled the package repository for my project. It is the setting at the bottom, am I correct?
  2. I don’t have 2FA active. Or at least I am not aware of it. I created a personal access token with full access to the API. That is the token that I am passing as an auth token. Based on the fact that I am getting the 400 Error I assume that it is not a problem with authentication, because in that case, it would be 401.
  3. Yes. Trust me, I checked it many times.
  4. No, I am not using Gitlab CI.

What happens if you replace this line with:
@lerna-experiment:registry”: “

BTW I’m also running into (separate) issues on publishing my first NPM package up to gitlab… wow it’s not simple!

Any progress here? Im running into similar issues.

I am also curious how you are supposed to handle spaces within group names when publishing to a group repository?

@ michalstrnad

The solution for me suggested by Gitlab support was you need to use to compile
image: node:14-slim
because I was using node latest and that image has some issues with the publishConfig.

Best regards,