adapter-vercel: ReferenceError when using fetch in hooks.js #3343
Labels
bug
Something isn't working
p1-important
SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone
Describe the bug
Referencing
fetch
at the top level ofhooks.js
throws aReferenceError: fetch is not defined
on every Serverless function invocation when deployed to Vercel. This only happens when deployed, and not when running locally withsvelte-kit dev
orsvelte-kit preview
.Reproduction
See my example repo. This is the SvelteKit demo app with a
console.log(fetch)
added in the root ofhooks.js
. Server-rendering a page (e.g. /todos) shows the below error page when deployed to Vercel.Logs
System Info
Severity
blocking an upgrade
Additional Information
This issue first presented with
adapter-vercel
, but I suspect it could be an issue with the other adapters as well.I think the issue is that fetch is not polyfilled until after the App is imported, at which point it's too late.
kit/packages/adapter-vercel/files/entry.js
Lines 1 to 6 in 9de8094
This issue came up when updating svelte.dev to latest SvelteKit.
hooks.js
imports a file that imports $lib/db/client, which referencesfetch
as part of an export.The text was updated successfully, but these errors were encountered: