Closed LiNCH35 closed 9 months ago
Hi. I cannot reproduce this issue using Node.js 16 and cluster preset on repo with pnpm nitro build --preset node_cluster test/fixture
.
Can you please remove your lockfile and reinstall all node_modules. We had some small fixes for fetch polyfill in node-fetch-native
you might be using a stalled one.
BTW please consider to migrate to Node.js v18 sooner as v16 is getting EOL very soon and node 18 has built-in fetch.
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
It is strange if _fetch
does not work also on Node.js 18! Thanks for explaining and putting time to make references. Feel free to share any updates you have here to help fixing it ASAP.
I don't know if this will help:
On version 2.5.2 in unenv global
has the following fields
'fetch', 'Blob', 'File', 'FormData', 'Headers', 'Request', 'Response'
on version 2.6.0 in.output/server/index.mjs
in global
does not have these fields.
Method createFetch
I am running into this too and managed to create a repro:
> preview
> node .output/server/index.mjs
Listening on http://[::]:3000
route called
[nitro] [request error] [unhandled] [GET] "http://localhost:3000/dum":
tested on node 16.19.1. node 18.17.1 worked for me (as in, showed the 404 as I expect)
node 16 migration is still underway at work because of the glibc requirement sadly...
did some digging in the code:
adding a `console.log(globalThis.fetch)` here https://github.com/unjs/nitro/blob/f126cbfe25faf6eac445d09e27a016016674a2f3/src/runtime/app.ts#L96 logs undefined on 16 and the expected asyncfunction on 18.
downgrading to nitro 2.5.2 it works as expected again, the log in that line logs the async function on 16, so somewhere between 2.5.2 and 2.6.2 the polyfill for fetch broke I guess?
not sure where to look from here, but maybe you got some pointers @pi0 (can also hit me up on discord `minidigger` on nuxt discord)
edit: updated my dev env to node 18 (after it worked locally), still not working (same fetch is not a function), I am going home.....
It is strange if
_fetch
does not work also on Node.js 18! Thanks for explaining and putting time to make references. Feel free to share any updates you have here to help fixing it ASAP.
mo too
same here on Node 20 and Nitro 2.7 (worked fine on Nitro 2.6)
nuxt | [nitro] [unhandledRejection] FetchError: [GET] "http://django:8000/bRs47jH13fdsBFMQ93/django/api/utils/sitemap": <no response> _fetch is not a function
nuxt | at async $fetchRaw2 (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:14)
nuxt | at async $fetch2 (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:261:15)
nuxt | at buildUrls (/app/utils/useSitemap.js:44:1)
nuxt | at useSitemap (/app/utils/useSitemap.js:243:1) {
nuxt | [cause]: TypeError: _fetch is not a function
nuxt | at ufetch (file:///app/node_modules/unenv/runtime/fetch/index.mjs:6:14)
nuxt | at localFetch (/app/node_modules/nitropack/dist/runtime/app.mjs:69:39)
nuxt | at $fetchRaw2 (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:219:32)
nuxt | at onError (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:158:16)
nuxt | at $fetchRaw2 (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:20)
nuxt | at async $fetch2 (file:///app/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:261:15)
nuxt | at buildUrls (/app/utils/useSitemap.js:44:1)
nuxt | at useSitemap (/app/utils/useSitemap.js:243:1)
nuxt | }
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 :D
Me too
The development environment is normal, but the production environment may experience the above errors
Environment Node: v18.17.0 Nuxt 3.8.0 with Nitro 2.7.2
Same here.
Nuxt 3.9.0 with Nitro 2.8.1.
Node v20.10.0
upd. Downgraded to Nuxt 3.6.5 with Nitro 2.5.2
– the error is still there
Same here. Nuxt: 3.8.2 with Nitro 2.8.1 , node version is 20.11.0
@xupapa please provide a reproduction 👍
I can't upgrade the node version yet. Is there any solution? The current version is 16.15.0
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:
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 🙏🏼
我的开发环境nodejs版本是20.12.2, 服务器线上nodejs版本是16, 在这种情况下会报错_fetch is not a function. 我尝试升级线上服务器的nodejs版本到20.12.2, 与开发环境保持一致, 问题就解决了. My development environment nodejs version is 20.12.2, and the server online nodejs version is 16, in which case I get an error '_fetch is not a function'. I tried upgrading the nodejs version of the live server to 20.12.2 to match the development environment, and the problem was solved.
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