Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response<string> returned rather than a json response #2315

Open
2 tasks done
gitgrimbo opened this issue Dec 3, 2023 · 2 comments
Open
2 tasks done

Response<string> returned rather than a json response #2315

gitgrimbo opened this issue Dec 3, 2023 · 2 comments

Comments

@gitgrimbo
Copy link

gitgrimbo commented Dec 3, 2023

Describe the bug

  • Node.js version: v20.8.1
  • OS & version: Windows 10

Actual behavior

Response<string> returned rather than a json response.

image

image

...

Expected behavior

Should return a response with a json() method, like in the repo readme example.

Code to reproduce

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "exports": "./index.js",
  "type": "module",
  "scripts": {
    "start": "node --loader ts-node/esm ./src/index.ts"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/got": "^9.6.12",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.3.2"
  },
  "dependencies": {
    "got": "^14.0.0"
  }
}

index.ts

import got from "got";

async function main() {
  const response = await got.post("https://httpbin.org/anything", {
    json: {
      hello: "world",
    },
  });
  console.log(response);
  console.log(response.json());
}

main();

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@Rot4tion
Copy link

https://www.npmjs.com/package/got-cjs
import got from "got-cjs";

@katsanva
Copy link
Contributor

@gitgrimbo you should specify responseType: "json" in options, see the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants