redbird icon indicating copy to clipboard operation
redbird copied to clipboard

[ERR_INVALID_ARG_TYPE]: The \"data\" argument must be of type string or an instance of Buffer, TypedArray, or DataView

Open nick-bull opened this issue 5 years ago • 7 comments

Getting the following errors:

{"level":50,"time":1595942893309,"pid":16805,"hostname":"ip-xxx-xx-xxx-xx","name":"redbird","code":"ERR_INVALID_ARG_TYPE","msg":"Error registering LetsEncrypt certificates","stack":"TypeError [ERR_INVALID_ARG_TYPE]: The \"data\" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined\n    at writeFile (fs.js:1385:5)\n    at internal/util.js:297:30\n    at new Promise (<anonymous>)\n    at writeFile (internal/util.js:296:12)\n    at Object.stageAsync (/home/ubuntu/proxy/node_modules/safe-replace/index.js:65:14)\n    at Object.writeFileAsync (/home/ubuntu/proxy/node_modules/safe-replace/index.js:57:18)\n    at /home/ubuntu/proxy/node_modules/le-store-certbot/index.js:288:19","type":"Error","v":1}
{"level":30,"time":1595942893309,"pid":16805,"hostname":"ip-xxx-xx-xxx-xx","name":"redbird","msg":"Could not get any certs for api.someurl.com","v":1}

from the following configuration:

const redbird = require('redbird');
const proxy = redbird({
  port: 80,
  letsencrypt: {
    path: __dirname + '/certs',
    port: 9999
  },
  ssl: {
    http2: true,
    port: 443,
  },
});

proxy.register('api.someurl.com', 'http://localhost:3002', {
  ssl: {
    letsencrypt: {
      email: '[email protected]',
      production: true,
    }
  }
});

What is the data argument? Why is it undefined? Am I meant to create the certificates manually? The certs directory exists, and looks as I'd expect for ACME.


node: v14.5.0 npm: 6.14.5 package.json:

{
  "name": "proxy",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "redbird": "^0.10.0"
  }
}

Tested with node 10.22.0, 12.18.3, and latest. No success

nick-bull avatar Jul 28 '20 13:07 nick-bull

I had this same issue and did some digging

turns out the error is on line 288 of le-store-certbot.

If I comment out the following lines:

/*   ............ around line 288 ................. */
var privkeyArchive = path.join(archiveDir, 'privkey' + checkpoints + '.pem'); 
//var bundleArchive = path.join(archiveDir, 'bundle' + checkpoints + '.pem'); //no longer used

return mkdirpAsync(archiveDir).then(function () { 
 return PromiseA.all([ 
   sfs.writeFileAsync(certArchive, pems.cert, 'ascii') 
 , sfs.writeFileAsync(chainArchive, pems.chain, 'ascii') 
 , sfs.writeFileAsync(fullchainArchive, [ pems.cert, pems.chain ].join('\n'), 'ascii') 
 , sfs.writeFileAsync(privkeyArchive, pems.privkey, 'ascii') 
//, sfs.writeFileAsync(bundleArchive, pems.bundle, 'ascii') // <-- comment this line
 ]); 
}).then(function () { 
 return mkdirpAsync(liveDir); 
}).then(function () { 

it works as expected.

furthermore I saw that this certbot store is deprecated, but le-store-fs is a drop in replacement.

https://www.npmjs.com/package/le-store-certbot

I would imagine it's just a case that le-store-certbot hasn't been touched in years, and the world of https has changed, and bundles are now a null response, which trips up the certbot-store.

I haven't checked if changing redbird over to le-store-fs will fix the issue, so if you want to check it and put in a pull request I'll let you have the claim to fame

for reference, redbird now registers https for me and is working as expected :)

Dotrar avatar Sep 02 '20 10:09 Dotrar

I faced the exactly same issue, thanks a lot @Dotrar for the fix 🙏 However, I believe that this issue should be fixed...

vastamaki avatar Nov 04 '22 05:11 vastamaki