npm / npm-registry-client

http://npm.im/npm-registry-client
ISC License
264 stars 108 forks source link

Unable to publish: incorrect header check #178

Closed emilsjolander closed 5 years ago

emilsjolander commented 5 years ago

I'm unable to publish a trivial node package due to Error: incorrect header check : @emilsj/publish-test. I've reduced it to a minimal example below (but ofc redacted my auth token). I've also tried updating the registry url to point to the full resource instead of the base registry url which still gives an error but this time results in a 404.

The code is modeled as closely as possible after the unit tests in this repo.

full error

ERR! publish Failed PUT 415
err: { Error: incorrect header check : @emilsj/publish-test
    at makeError (/Users/emilsjolander/npm-publish-test/node_modules/npm-registry-client/lib/request.js:329:12)
    at RegClient.<anonymous> (/Users/emilsjolander/npm-publish-test/node_modules/npm-registry-client/lib/request.js:317:14)
    at Request._callback (/Users/emilsjolander/npm-publish-test/node_modules/npm-registry-client/lib/request.js:216:14)
    at Request.self.callback (/Users/emilsjolander/npm-publish-test/node_modules/request/request.js:185:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (/Users/emilsjolander/npm-publish-test/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:189:13)
    at IncomingMessage.<anonymous> (/Users/emilsjolander/npm-publish-test/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15) pkgid: '@emilsj/publish-test', statusCode: 415, code: 'E415' }

package.json

{
  "name": "@emilsj/publish-test",
  "version": "0.0.1",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "npm-registry-client": "^8.6.0",
  }
}

index.js

const Registry = require('npm-registry-client');
const fs = require('fs');

var bodyPath = require.resolve('./package.json')
var tarball = fs.createReadStream(bodyPath)
var pkg = require('./package.json')

var params = {
  metadata: pkg,
  access: 'public',
  body: tarball,
  auth: { token: "REDACTED" }
}

const client = new Registry({});
const uri = "https://registry.npmjs.org/";

client.publish(uri, params, console.log);
emilsjolander commented 5 years ago

Re-wrote example slightly to use https://github.com/npm/libnpmpublish instead and getting very similar error. So assuming not a direct issue with this package but maybe rather with the data I'm passing in. However the data passed in very closely matches unit tests provided in this package.

emilsjolander commented 5 years ago

Ok finally figured out the issue! I had only created a tarball but the registry expects a gziped tarball! Using Zlib to gzip the stream solved my issue

failedUser commented 5 years ago

thanks, I reoslve my problem since I find this Issue; let gzip = zlib.createGzip(); body: fs.createReadStream(bodyPath).pipe(gzip);