question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FetchError: invalid-json

See original GitHub issue

I have a Discord Bot and on my Windows 10 64x PC it works fine, but on my VM Debian 10 Server i got the following error and I dont know why. If i run on my computer(Windows 10 VSC Debugger) the

image

but on my VM (Debian 10)

image

tbh i dont know why it works on my pc fine and on my server i got the error with the same packages and versions

Error:

/home/lennart/Discordbots/v2/node_modules/node-fetch/lib/index.js:272
                                return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
                                                           ^
FetchError: invalid json response body at https://karmatop.de/addon/pxl-api.php?name=L3nnart_ reason: Unexpected token < in JSON at position 0
    at /home/lennart/Discordbots/v2/node_modules/node-fetch/lib/index.js:272:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'invalid-json'
}

Example Code

const url = `https://karmatop.de/addon/pxl-api.php?name=` + spieler; //spieler is a variable/argument from the discord bot, for example  "L3nnart_"
            fetch(url, {
                method: "GET",
                headers: {
                    Accept: "application/json",
                },
            })

Your Environment

software version
node-fetch 2.6.1
node 16.8
npm 7.21.0
Operating System Deabian/Windows

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
jimmywartingcommented, Mar 11, 2022

Bumping the wrong issue… should maybe bump #541 with a potential fix: https://github.com/node-fetch/node-fetch/pull/1482

1reaction
autukillcommented, Mar 11, 2022

My nodejs app recently crashed due to node-fetch, The exception is the same as you

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid json response body error with Express node-fetch ...
Try res => console.log(res) in your first .then() block to see what the response is. Usually that error "Unexpected token < in JSON....
Read more >
invalid json response body at...reason: Unexpected token < in ...
Is there any solution for this error? FetchError: invalid json response body at http://mydomain.com/graphql reason: Unexpected token < in JSON ...
Read more >
Npm Err Invalid Json Response Body Unexpected End of ...
Just run the following command, to clear you local npm cache folder. ... That kind of error, happened when your network is not...
Read more >
fetcherror: invalid response body while trying to fetch - You.com
The error is triggered because you are getting a HTML response instead of JSON. If you make the request from the browser you...
Read more >
Connectivity | EOSIO Developer Docs
invalid json response body ... This typically means you have connected to a computer that is not running EOSIO software. For example, if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found