unjs / unenv

๐Ÿ•Š๏ธ Convert javaScript code to be runtime agnostic
MIT License
348 stars 18 forks source link

Add missing kOutHeaders property #164

Closed tomaratyn closed 4 months ago

tomaratyn commented 4 months ago

The absence of this property caused Node's OutgoingMessage.prototype.setHeader function to fail as it checks for null but not for falsey or undefined.

When setHeader fails with unenv then nuxt can have problems properly rendering error pages for API routes/middleware.

๐Ÿ”— Linked issue

โ“ Type of change

๐Ÿ“š Description

The current re-implementation of ServerResponse is missing the property kOutHeaders. The absence of this property means that it's undefined but Node tests using === null to check if the value needs to be initialized (see https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L709).

Due to this when a Nuxt server route has an error it can fail to render since Nuxt will use Nitro's localFetch which in turn uses unenv's createFetch which in turn uses unenv's ServerResponse.

๐Ÿ“ Checklist

tomaratyn commented 4 months ago

Actually that property can't be a string, it has to be a Symbol that is not exported by Node. This approach won't work.