alexrsagen/node-es6-request

this.destroy is not a function

Closed this issue · 6 comments

I have this mistake:
TypeError /app/node_modules/es6-request/index.js:168

when I use:

return request.get('http://mydomain.com/test')
      .headers({
        'Content-Type': 'application/json'
      })
      .then(([body, res]) => {

      })
      .catch((err) => {
        console.error('problem with request: ' + err.message);
        return err;
      });

More details about the error:

/app/node_modules/es6-request/index.js:168
          this.destroy();
               ^

TypeError: this.destroy is not a function
    at IncomingMessage.res.on (/app/node_modules/es6-request/index.js:168:16)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Is it normal that in the index.js of node-es6-request line 124, the function is _destroy() { instead of destroy() {?

UPDATE
If I rename the function _destroy by destroy in the index.js of node-es6-request line 124, the error disappears.

I created a pull request #7

That's not a proper solution. The Request class extends a Node.js Duplex stream, which implements the destroy method which in turn calls my _destroy function.

What Node.js version are you running?

Node.js v6.11.1

That's most likely your problem then. Node.js v8.x.x should work fine.

In this case, can you add in your package.json

"engines": {
    "node": "^8.1"
}

Sure! Thanks for letting me know.

I confirm, the error doesn't appear with Node.js v8.1.4