sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Can't get GOT to send simple GET requests #1071

Closed carefulcomputer closed 4 years ago

carefulcomputer commented 4 years ago

Describe the bug

Actual behavior

Getting error..

{ GotError: The "listener" argument must be of type Function. Received type object at get (/Users/user/Documents/gotTest/node_modules/got/dist/source/request-as-event-emitter.js:199:27) at ClientRequest.once (events.js:288:11) at new ClientRequest (_http_client.js:141:10) at Object.request (https.js:272:10) at get (/Users/user/Documents/gotTest/node_modules/got/dist/source/request-as-event-emitter.js:196:65) name: 'RequestError', code: 'ERR_INVALID_ARG_TYPE' }

Expected behavior

Response from website. ...

Code to reproduce

const got = require('got');

(async () => {
    try {
        const body = await got('https://teasdfasd2er.free.beeceptor.com');
        console.log(body);
    } catch (error) {
        console.log(error);
    }
})();

Package.json

{
  "name": "gotTest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "got": "^10.5.5"
  }
}

Checklist

sindresorhus commented 4 years ago

Your Node.js 10.x version is very old. Try upgrading to the latest Node.js 10 version, or preferably 12. There have been a lot of Node.js bug fixes since Node.js 10.4.

carefulcomputer commented 4 years ago

yup.. upgrading node to latest version fixed it.