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

TypeError: fetch failed #26883

Closed
ElYaiko opened this issue Apr 22, 2024 · 3 comments
Closed

TypeError: fetch failed #26883

ElYaiko opened this issue Apr 22, 2024 · 3 comments

Comments

@ElYaiko
Copy link

ElYaiko commented Apr 22, 2024

Environment

  • Operating System: Darwin
  • Node Version: v18.17.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: bun@1.1.4
  • Builder: -
  • User Config: devtools, alias, app, runtimeConfig, css, build, modules, experimental, features, vite, nitro
  • Runtime Modules: @pinia/nuxt@0.4.11
  • Build Modules: -

Reproduction

Describe the bug

I have a $fetch that checks inside an api route a recaptcha response:

          const r = await $fetch<{
            success: boolean
            hostname?: string
            'error-codes'?: string[]
          }>('https://www.google.com/recaptcha/api/siteverify', {
            method: 'post',
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: new URLSearchParams({
              secret: captchaKey.re,
              response: val
            })
          });

For some reason the build in my ssh server gets:

Api error: FetchError: [POST] "https://www.google.com/recaptcha/api/siteverify": <no response> fetch failed
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at r (file:///var/www/server/index.mjs:1:59455)
    ... 5 lines matching cause stack trace ...
    at Object.handler (file:///var/www/server/index.mjs:1:51201)
    at Server.<anonymous> (file:///var/www/server/index.mjs:1:54023) {
  [cause]: TypeError: fetch failed
      at Object.fetch (node:internal/deps/undici/undici:11730:11)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at $fetchRaw (file:///var/www/server/index.mjs:1:58493)
      at r (file:///var/www/server/index.mjs:1:59455)
      at Object.refinement (file:///var/www/server/utils/zod.ts:264:1)
      at file:///var/www/server/node_modules/zod-abort-failed/lib/index.mjs:1971:39
      at ZodObject.safeParseAsync (file:///var/www/server/node_modules/zod-abort-failed/lib/index.mjs:655:24)
      at ZodObject.password (file:///var/www/server/node_modules/zod-abort-failed/lib/index.mjs:628:24)
      at Object.handler (file:///var/www/server/api/auth/index.post.ts:17:1)
      at Object.handler (file:///var/www/server/index.mjs:1:51201) {
    cause: ConnectTimeoutError: Connect Timeout Error
        at onConnectTimeout (node:internal/deps/undici/undici:6869:28)
        at node:internal/deps/undici/undici:6825:50
        at Immediate._onImmediate (node:internal/deps/undici/undici:6857:13)
        at processImmediate (node:internal/timers:476:21) {
      code: 'UND_ERR_CONNECT_TIMEOUT'
    }
  }
} undefined undefined

I did the same request with curl and has no problem so I guess is some package issue...

Additional context

No response

Logs

No response

Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@manniL
Copy link
Member

manniL commented Apr 22, 2024

I don't think it is a package error. If you can successfully do the request with the plain fetch api (not $fetch), it might be, but most likely it is either a browser extension blocking the request or some logic error.

@ElYaiko
Copy link
Author

ElYaiko commented Apr 30, 2024

Sorry, I tried with fetch and figured out it was an Ipv6 problem with my server.
Thanks.

@ElYaiko ElYaiko closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants