Document that vercel functions should be created as SvelteKit endpoints
See original GitHub issueHello team 👋, really enjoying the svelte-kit experience so far!
One thing I noticed is when using vercel’s serverless functions alongside a svelte-kit app there are a few nuances and unintended side effects, namely with client-side code not executing in local dev when svelte-kit is wrapped with vercel dev
minimal example repo: https://github.com/josefaidt/svelte-kit-vercel-local-issue
With vercel dev
which executes svelte-kit dev -p $PORT
and gives us the API routes
With svelte-kit dev
, no API routes
When the application is deployed to vercel, everything appears fine! This seems to only affect local development.
- Live implementation: https://sk-vercel-local-issue.vercel.app/
- Live API route: https://sk-vercel-local-issue.vercel.app/api/hello
I’ve since found a way around this behavior and I am fully aware svelte-kit is in beta so this will likely change, however I wanted to bring it up and reach out in case I am going against the grain with this setup.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:13 (6 by maintainers)
Top GitHub Comments
Hello, jumping in here to discuss a bit about serverless functions with sveltekit and vercel (and possibly others?).
I think there are 2 downsides of the current output of sveltekit endpoints functions with sveltekit. Currently endpoints hide behind the functions/render/index.js file, and from what I understand (see here), this creates only 1 serverless function, this issues are:
Edit: There’s also the problem of cold boot time. I assume it would be slower to boot a 10 sveltekit function bundle, than just 1.
Let me know if I’m making the right assumptions, or if there is some code that I’m not seing that splits the render/index.js file into multiple vercel (AWS) functions.
Just in order to manage expectations here, I didn’t consider vercel API functions at all when writing this adapter. It’s not that we can’t support them, they just aren’t something we expect to work right now. If they do, that’s pure chance.
After a chat with Leo from Vercel, the recommendation is to use Svelte Kit’s endpoints to write functions in, and not use the Vercel provided functionality - Vercel functions are really intended as helpers if your chosen framework doesn’t include a way to write serverless functions (or it is the blessed way to write serverless functions as it is in nextjs).