Skip to content

Bad request error 400 when publishing to npm packages

backend-weight2

Summary

I'm trying to publish a private package to our gitlab repo. But I keep getting the 400 bad request error. I just followed the tutorial on: https://docs.gitlab.com/12.5/ee/user/packages/npm_registry/index.html

Steps to reproduce

  1. Create a gitlab repo
  2. Initialize node project
  3. Add the following to the package.json
"publishConfig": {
    "@<YOUR_ORGANIZATION>:registry": "https://gitlab.com/api/v4/projects/<your_project_id>/packages/npm/"
  }
  1. Create a .npmrc file where the following code needs to be added
//gitlab.com/api/v4/packages/npm/:_authToken=<YOUR_AUTH_TOKEN>
//gitlab.com/api/v4/projects/<YOUR_PROJECT_ID>/packages/npm/:_authToken=<YOUR_AUTH_TOKEN>
@<YOUR_ORGANIZATION>:registry=https://gitlab.com/api/v4/packages/npm/
always-auth=true
  1. Try the following command in the command line:
npm publish

What is the current bug behavior?

When trying the publish the package to the gitlab repository, I receive the following error:

npm ERR! code E400
npm ERR! 400 Bad Request - PUT https://gitlab.com/api/v4/projects/<project_id>/pacckages/npm/@ihomer%2fexport-as

What is the expected correct behavior?

The package needs to be published to our repo

Relevant logs and/or screenshots

Output log:

npm info it worked if it ends with ok
npm verb cli [
npm verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\gewoo\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'publish',
npm verb cli   '--verbose'
npm verb cli ]
npm info using npm@6.13.1
npm info using node@v12.13.1
npm verb npm-session 50d2455a7d29e713
npm verb publish [ '.' ]
npm info lifecycle @ihomer/export-as@1.0.0~prepublish: @ihomer/export-as@1.0.0
npm info lifecycle @ihomer/export-as@1.0.0~prepare: @ihomer/export-as@1.0.0
npm info lifecycle @ihomer/export-as@1.0.0~prepublishOnly: @ihomer/export-as@1.0.0
npm info lifecycle @ihomer/export-as@1.0.0~prepack: @ihomer/export-as@1.0.0
npm info lifecycle @ihomer/export-as@1.0.0~postpack: @ihomer/export-as@1.0.0
npm notice
npm notice package: @ihomer/export-as@1.0.0
npm notice === Tarball Contents ===
npm notice 623B  check.js
npm notice 1.0kB sub.js
npm notice 989B  jwks.json
npm notice 434B  package.json
npm notice === Tarball Details ===
npm notice name:          @ihomer/export-as
npm notice version:       1.0.0
npm notice package size:  1.8 kB
npm notice unpacked size: 3.1 kB
npm notice shasum:        42bcbe08d7a6bf0146fb9c60a50a9432b72acbb4
npm notice integrity:     sha512-5/AwdrWyA+/Vl[...]EsajAfkt2xzPw==
npm notice total files:   4
npm notice
npm http fetch PUT 400 https://gitlab.com/api/v4/projects/15071328/packages/npm/@ihomer%2fexport-as 543ms
npm verb stack Error: 400 Bad Request - PUT https://gitlab.com/api/v4/projects/15071328/packages/npm/@ihomer%2fexport-as
npm verb stack     at C:\Users\gewoo\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-fetch\check-response.js:104:15
npm verb stack     at processTicksAndRejections (internal/process/task_queues.js:93:5)
npm verb statusCode 400
npm verb pkgid @ihomer/export-as@1.0.0
npm verb cwd C:\Users\gewoo\Desktop\IHomer\Transform-service\Project\Export-as\lambda-functions\api\export-as-lib
npm verb Windows_NT 10.0.17134
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\gewoo\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "publish" "--verbose"
npm verb node v12.13.1
npm verb npm  v6.13.1
npm ERR! code E400
npm ERR! 400 Bad Request - PUT https://gitlab.com/api/v4/projects/15071328/packages/npm/@ihomer%2fexport-as
npm verb exit [ 1, true ]
npm timing npm Completed in 1933ms

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\gewoo\AppData\Roaming\npm-cache\_logs\2019-11-26T16_02_25_401Z-debug.log

files

package.json

{
  "name": "@ihomer/export-as",
  "version": "1.0.0",
  "description": "",
  "main": "check.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Jordy",
  "license": "ISC",
  "dependencies": {
    "jsonwebtoken": "^8.5.1",
    "jwk-to-pem": "^2.0.1",
    "mysql": "^2.17.1"
  },
  "publishConfig": {
    "@ihomer:registry": "https://gitlab.com/api/v4/projects/15071328/packages/npm/"
  }
}

.npmrc

//gitlab.com/api/v4/packages/npm/:_authToken=<auth_token>
//gitlab.com/api/v4/projects/15071328/packages/npm/:_authToken=<auth_token>
@ihomer:registry=https://gitlab.com/api/v4/packages/npm/
always-auth=true
Edited by Tim Rizzi