kit icon indicating copy to clipboard operation
kit copied to clipboard

Add ability to disable Node polyfills

Open pzuraq opened this issue 2 years ago • 9 comments

Describe the problem

We've been using Mock Service Worker to mock out requests to our backend. We use the Node interceptor for it so that the mocks work in both SSR and on the client. However, when we recently started updating our SvelteKit version, we noticed that this stopped working. We think that this is due to the Undici polyfill, which appears to completely avoid standard global Node modules like http and https.

In addition, the error logs for these mocked libraries and significantly harder to read and debug, as they use a few tricks for scheduling that make the original call site difficult to find.

Describe the proposed solution

Modern versions of Node (e.g. Node 18) have all of the mocked libraries available as globals by default, so there is no need to mock them. I propose either adding an option to disable the polyfills manually, or ignoring the polyfill if a global version exists already.

Alternatives considered

None

Importance

would make my life easier

Additional Information

No response

pzuraq avatar Oct 24 '22 20:10 pzuraq

For reference, Node 18 has been available since April, 2022. However, AWS Lambda does not yet support Node 18. Based on past history, it usually takes them about a year to add support.

benmccann avatar Nov 09 '22 00:11 benmccann

Re-opening — #7668 caused #7673

Rich-Harris avatar Nov 16 '22 15:11 Rich-Harris

(we should add a multipart test before attempting this again)

Rich-Harris avatar Nov 16 '22 15:11 Rich-Harris

After discussion, we agreed to add a polyfill: false option (or similar) to adapter-node, so that the polyfills can be excluded from server code altogether where applicable.

Rich-Harris avatar Nov 26 '22 17:11 Rich-Harris

Removing from the 1.0 milestone since this update won't affect Kit itself

Rich-Harris avatar Nov 27 '22 16:11 Rich-Harris

For reference, Node 18 has been available since April, 2022. However, AWS Lambda does not yet support Node 18. Based on past history, it usually takes them about a year to add support.

Looks like AWS Lambda now supports node 18

bluwy avatar Nov 29 '22 06:11 bluwy

I just tried Netlify. It still uses Node 16 by default, but does support Node 18.

benmccann avatar Nov 29 '22 15:11 benmccann

After discussion, we agreed to add a polyfill: false option (or similar) to adapter-node, so that the polyfills can be excluded from server code altogether where applicable.

We are using adapter-cloudflare-workers where this is happening - can we also have an option to disable polyfills there?

chronicIntrovert avatar Dec 05 '22 15:12 chronicIntrovert

adapter-cloudflare-workers doesn't add polyfills. You must be experiencing something else

Rich-Harris avatar Dec 09 '22 21:12 Rich-Harris