Direct fetch is incompatible with express.js
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the reproduction and the linked unenv runtime/fetch/call.ts and Nitro src/types/runtime/nitro.ts entry points. Trace which request and response implementations direct local fetch uses, then verify the Express prototype setup no longer causes res.setHeader to throw and that local request errors can be sent correctly.
Written by the indexing model from the issue text.
Description
Environment
Nuxt with default node env
Reproduction
import createApp from 'express';
import {IncomingMessage} from 'unenv/runtime/node/http/_request'
import {ServerResponse} from 'unenv/runtime/node/http/_response'
const req = new IncomingMessage();
const res = new ServerResponse(req);
// Taken from express init middleware implementation
const app = createApp();
Object.setPrototypeOf(res, app.response);
res.setHeader('vary', 'test'); // TypeError: Cannot set properties of undefined (setting 'vary')
Describe the bug
When sending a local request to an express server using fetch, a server error occurs
Additional context
This is very problematic in nuxt with useFetch and a legacy endpoint that uses an express server behind the scenes (This issue took me about 20h to debug because it's such a complex chain of events to follow and the errors hidden behind 3 layers could not even be sent properly because the response object was broken)
It seems the problem is that unenv's fetch always uses its internal node/http/request,response even if build with the node env preset and this is problematic because then local requests behave differently than external requests
https://github.com/unjs/unenv/blob/main/src/runtime/fetch/call.ts#L1-L2
unenv's fetch is then used by nitro even if env is set to node
https://github.com/unjs/nitro/blob/a399e189576d4c18d7f837bd454e0503e1f53980/src/types/runtime/nitro.ts#L7
Logs
No response
- Dominant language
- TypeScript
- Stars
- 17
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from unjs/node-mock-http
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
unjs/node-mock-http#38 ·
-
Dependency Dashboard Open
Difficulty 3/5 1-2 days Newbie friendliness 15/100
unjs/node-mock-http#2 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
unjs/node-mock-http#6 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
unjs/node-mock-http#9 · 2 comments · 3 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
unjs/node-mock-http#7 · 1 comment ·
All issues in unjs/node-mock-http
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·