nitro: _fetch is not a function. In build

Environment

Nitro: v2.6.0 Node: v16.16.0

NITRO_PRESET=node_cluster

Reproduction

Only build mode. I couldn’t reproduce

Describe the bug

Downgrading to 2.5.2 or disabling node_cluster may help

Additional context

No response

Logs

TypeError: _fetch is not a function
0|Front2  | 2023-08-24T18:47:12:     at ufetch (file:///var/www/a_front2/.output/server/index.mjs:3002:14)
0|Front2  | 2023-08-24T18:47:12:     at localFetch (file:///var/www/a_front2/.output/server/index.mjs:17261:12)
0|Front2  | 2023-08-24T18:47:12:     at $fetchRaw2 (file:///var/www/a_front2/.output/server/index.mjs:2877:32)
0|Front2  | 2023-08-24T18:47:12:     at $fetch2 (file:///var/www/a_front2/.output/server/index.mjs:2919:21)
0|Front2  | 2023-08-24T18:47:12:     at useVzFetch (file:///var/www/a_front2/.output/server/chunks/app/server.mjs:4920:10)
0|Front2  | 2023-08-24T18:47:12:     at file:///var/www/a_front2/.output/server/chunks/app/server.mjs:7694:12
0|Front2  | 2023-08-24T18:47:12:     at _loadData (file:///var/www/a_front2/.output/server/node_modules/@vueuse/core/index.mjs:4544:20)

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 1
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I think I know the reason. I compiled it locally with Nodejs18, and then used scp to transfer it to the server. The nodejs version of the server is 16, so an error was reported. I also switched to nodejs16 locally and compiled it, and no errors were reported.

I know it is a painful situation for some deployment flows but please consider:

  • Use Node 18 or 20 (not 16) – 16 is already EOL and we only have best effort support for it
  • Use same Node version that you build project with as you deploy with

It is not easy to track in one issue because different deployment situations are different.

If you are stuck with this issue even checking both requirements above, please use a new issue with reproduction so we can properly investigate each one by one 🙏🏼

solved it, sorry it was my old code

I had this set in my Dockerfile ENV NODE_OPTIONS=\"--no-experimental-fetch\"

not removing fetch from Node fixed my issue 😄

Hi. We put the project on an empty virtual machine with node 16 and node 18. The result was the same. Tried to reproduce purely nitro and really did not give errors. Maybe the problem is nuxt when it uses nitro ^2.6.0? Here is a similar problems: https://github.com/nuxt/nuxt/issues/22816 https://github.com/nuxt/nuxt/issues/22783

I will try to reproduce it later