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.

TypeError: fetch failed

See original GitHub issue

Bug Description

Fetch throws ‘TypeError: fetch failed’ when posting

Reproducible By

Request with private production credentials to ERP

Expected Behavior

Successful response (ok). node-fetch works just fine.

Logs & Screenshots

 TypeError: fetch failed
    at Object.processResponse (C:\Users\kyryl\dev\entriwise\server\node_modules\undici\lib\fetch\index.js:183:23)
    at Fetch.fetchFinale (C:\Users\kyryl\dev\entriwise\server\node_modules\undici\lib\fetch\index.js:937:17)
    at Fetch.mainFetch (C:\Users\kyryl\dev\entriwise\server\node_modules\undici\lib\fetch\index.js:744:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Environment

Linux and Windows, v17.5 v17.6

Additional context

Request takes up to several minutes until response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:33 (25 by maintainers)

github_iconTop GitHub Comments

5reactions
akauppicommented, Feb 27, 2022

Maybe this can help?

I am experiencing the same with a Firebase Emulators host.

$ git clone https://github.com/akauppi/firebase-jest-testing.git
$ cd firebase-jest-testing

$ git checkout 0d2a5f43022453a34a3de9510f9e436b4d890078    # reproducible in this commit

$ npm install

In one terminal:

$ npm run start

In another:

$ npm run test:fns:greet
...
(node:37466) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 FAIL  sample/test-fns/greet.test.js
  Cloud Function callables
    ✕ returns a greeting (15 ms)

  ● Cloud Function callables › returns a greeting

    TypeError: fetch failed

      at Object.processResponse (../../node_modules/undici/lib/fetch/index.js:183:23)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.324 s, estimated 1 s
Ran all test suites matching /greet.test.js/i.

Added: Once npm run start is running, you can exercise the server by:

$ curl -v -X POST -d '{"data":"abc"}' -H "Content-type: application/json" http://localhost:5002/demo-1/mars-cent
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1:5002...
* connect to ::1 port 5002 failed: Connection refused
*   Trying 127.0.0.1:5002...
* Connected to localhost (127.0.0.1) port 5002 (#0)
> POST /demo-1/mars-central2/greet HTTP/1.1
> Host: localhost:5002
> User-Agent: curl/7.77.0
> Accept: */*
> Content-type: application/json
> Content-Length: 14
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< x-powered-by: Express
< vary: Origin
< content-type: application/json; charset=utf-8
< content-length: 28
< etag: W/"1c-90pTE8vnJrTHpo49hh2KVRcGoxw"
< date: Sun, 27 Feb 2022 12:33:58 GMT
< connection: close
< 
* Closing connection 0
{"result":"Greetings, abc."} 

Trying with 127.0.0.1 instead of localhost puts the problem at rest:

$ EMUL_HOST=127.0.0.1 npm run test:fns:greet

> test:fns:greet
> NODE_OPTIONS=--experimental-vm-modules jest --config sample/test-fns/jest.config.js -f greet.test.js --verbose --all

(node:38224) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:38224) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
 PASS  sample/test-fns/greet.test.js
  Cloud Function callables
    ✓ returns a greeting (33 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.32 s, estimated 1 s
Ran all test suites matching /greet.test.js/i.
4reactions
kyrylkovcommented, Apr 26, 2022

@ronag I’m still having these errors. Cannot use undici fetch at all. Here is updated trace from Node v18:

TypeError: fetch failed
    at Object.processResponse (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:200:23)
    at /home/ubuntu/server/node_modules/undici/lib/fetch/index.js:941:38
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    ... 2 lines matching cause stack trace ...
    at process.processTimers (node:internal/timers:507:7) {
  cause: Error: [object Object]
      at makeNetworkError (/home/ubuntu/server/node_modules/undici/lib/fetch/response.js:366:11)
      at httpNetworkFetch (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:1751:12)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at runNextTicks (node:internal/process/task_queues:64:3)
      at listOnTimeout (node:internal/timers:533:9)
      at process.processTimers (node:internal/timers:507:7)
      at async httpNetworkOrCacheFetch (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:1440:29)
      at async httpFetch (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:1028:33)
      at async schemeFetch (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:888:14)
      at async /home/ubuntu/server/node_modules/undici/lib/fetch/index.js:569:16
      at async mainFetch (/home/ubuntu/server/node_modules/undici/lib/fetch/index.js:553:16) {
    [cause]: undefined
  }
}

@ronag Could you re-open or reply to my emails?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "TypeError: Failed to fetch" when the request hasn't ...
Check the value of Access-Control-Allow-Origin in the response headers. Usually fetch API will throw fail to fetch even after receiving a ...
Read more >
TypeError: Failed to fetch and CORS in JavaScript | bobbyhadz
TypeError : Failed to fetch and CORS in JavaScript # · An incorrect or incomplete URL has been passed to the fetch() method....
Read more >
Undocumented TypeError: Failed to fetch
I have to go to console , hit the URL appear then click on "advanced" in the browser > then click on "process"...
Read more >
Type Error: Failed to Fetch when using Fetch API - JavaScript
fetch will reject with a TypeError when a network error is encountered. Check you are running the json server correctly and that it...
Read more >
What do I do if "TypeError: Failed to fetch" is displayed when I ...
Object Storage Service:What do I do if "TypeError: Failed to fetch" is displayed when I use a browser to access a bucket or...
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 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