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

with-msw: Cannot use fetch in node? #37300

Closed
1 task done
PeterlitsZo opened this issue May 30, 2022 · 6 comments
Closed
1 task done

with-msw: Cannot use fetch in node? #37300

PeterlitsZo opened this issue May 30, 2022 · 6 comments
Labels
examples Issue/PR related to examples locked

Comments

@PeterlitsZo
Copy link

PeterlitsZo commented May 30, 2022

UPDATE: Maybe it is a bug(?) of MSW. @s-bilic tell me that we can switch node's version from v18 to v16. I never try. But I promise that I will try tonight (tonight in my area 🤣 ).

$ nvm install v16.0
$ nvm use v16.0

Done. This works. It is not a bug of next.js, it is a... emmm... bug(?) of MSW.


Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

    Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT Wed May 18 09:20:01 UTC 2022
    Binaries:
      Node: 18.2.0
      npm: 8.5.5
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 12.1.6
      react: 17.0.2
      react-dom: 17.0.2

I also try in [email protected].

Which example does this report relate to?

with-msw

What browser are you using? (if relevant)

Firefox (100.0.2). Chrome(101.0.4951.41 beta)

How are you deploying your application? (if relevant)

Just next

Describe the Bug

I run the code below:

$ npx create-next-app --example with-msw with-msw-app
$ cd with-msw-app
$ yarn
$ yarn dev

Then it raises two errors. The second tells me that the msw needs be inited. So I run code below:

$ npx msw init public/ --save

And now it only raise one error:

(in page)
Server Error
TypeError: fetch failed
This error happened while generating the page. Any console logs will be displayed in the terminal window.

(in console)
error - TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:5570:34)
    at node:internal/deps/undici/undici:5896:42
    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 process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: getaddrinfo ENOTFOUND my.backend
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:83:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'my.backend'
  },
  page: '/'
}

Expected Behavior

I hope there is no error at all.

To Reproduce

$ npx create-next-app --example with-msw with-msw-app
$ cd with-msw-app
$ yarn
$ npx msw init public/ --save
$ yarn dev

By the way, I still do not get why we need to use the function fetch in node.js environment...

@PeterlitsZo PeterlitsZo added the bug Issue was opened via the bug report template. label May 30, 2022
@balazsorban44 balazsorban44 added examples Issue/PR related to examples and removed bug Issue was opened via the bug report template. labels May 30, 2022
@johnnypea
Copy link

Any update, please?

@s-bilic
Copy link

s-bilic commented Jul 19, 2022

Had the same issue, switched from node v18 to v16 as a temp workaround.

@PeterlitsZo
Copy link
Author

Had the same issue, switched from node v18 to v16 as a temp workaround.

Oh yeah. I remember that MSW works on v16. Maybe we need just wait or switch to v16.

@kettanaito
Copy link
Contributor

MSW doesn't support Node.js 18 yet. There's a big effort around that support from our contributors (see mswjs/msw#1388). For now, use a supported Node.js version range, which is v14-v17.

@balazsorban44
Copy link
Member

See mswjs/msw#1388 (comment)

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples locked
Projects
None yet
Development

No branches or pull requests

5 participants