fix: fallback to undiciFetch when globalThis.fetch is unavailable#840
fix: fallback to undiciFetch when globalThis.fetch is unavailable#840deep-innovator wants to merge 1 commit intojackwener:mainfrom
Conversation
Resolves compatibility issue on Windows with older Node.js versions where `globalThis.fetch` is not available at module load time. This change keeps the original `nativeFetch` function signature unchanged, preserving the no-proxy path behavior while adding a synchronous fallback to `undiciFetch`.
|
I reproduced the current failure by deleting One thing still missing is a regression test for the no- Also worth confirming the support target here. |
|
Thanks for the review! I'll wait for your further guidance on this
…---- Replied Message ----
| From | ***@***.***> |
| Date | 04/07/2026 20:43 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [jackwener/opencli] fix: fallback to undiciFetch when globalThis.fetch is unavailable (PR #840) |
Astro-Han left a comment (jackwener/opencli#840)
I reproduced the current failure by deleting globalThis.fetch before importing src/node-network.ts. On main, that throws at the eager bind, so this PR is fixing the right spot.
One thing still missing is a regression test for the no-fetch module-load path. The current tests cover proxy decisions after import, but not the startup case this change is meant to fix.
Also worth confirming the support target here. package.json still says node >=20, so this is either a best-effort compatibility fix for unsupported runtimes or a sign that the engine floor should be revisited.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
| const directDispatcher = new Agent(); | ||
| const proxyDispatcherCache = new Map<string, Dispatcher>(); | ||
| const nativeFetch = globalThis.fetch.bind(globalThis); | ||
| const nativeFetch = globalThis.fetch |
There was a problem hiding this comment.
Would it be simpler to make nativeFetch a tiny wrapper instead of choosing once at module load? As written, if fetch is missing during import but gets installed later, the direct path is still pinned to undiciFetch for the rest of the process.
Problem
On Windows with older Node.js versions,
globalThis.fetchis not available at module load time, causing the originalnativeFetchdefinition to fail immediately.Solution
nativeFetchas a direct request function, preserving the original signature(input, init) => Promise<Response>.undiciFetchsynchronously whenglobalThis.fetchis unavailable.Verification
return nativeFetch(input, init).fetchand theundiciFetchfallback.