bun
bun copied to clipboard
Create Sveltekit Apps using Bun
What is the problem this feature will solve?
We need to have Svelte to be included in the project creation step to make it easy to using Bun to create Sveltekit apps.
What is the feature you are proposing to solve the problem?
We need bun create svelte ./app to make it easy to create a new svelte project
What alternatives have you considered?
No response
@niiwade Would you like to create a PR for this?
yes sure
note that there is a community adapter here you can maybe crib from https://github.com/gornostay25/svelte-adapter-bun
note that there is a community adapter here you can maybe crib from https://github.com/gornostay25/svelte-adapter-bun
Thank you @sw-yx , am checking it out
Any good news on SvelteKit + bun runtime?
This would be a great framework to get first class support for in bun.

Status on SvelteKit:
- It depends on
worker_threads, though not much of it. JustparentPortandnew Worker, and passingenvdata. - Since we do not export anything in
worker_threads, it causes vite to crash loading the config file.
SvelteKit is now working with bun upgrade --canary until v0.7.2 is released 🚀
EDIT: There is still some work to be done see https://github.com/oven-sh/bun/issues/600#issuecomment-1664814473.
This was a nice surprise. Thanks for commenting @hanssonduck . Looks like there are some minor console tty issues on Vite and some HMR issues too, although fair to say those are not SvelteKit directly. On a starter app built from the Svelte bootstrapping command, I have success. On a more complex app, I have hanging requests. Not sure why yet. But overall getting closer!!
Worker threads got it so importing sveltekit stopped throwing, which gets us past the vite config load step.
But
We're not fully there yet, unfortunately. I've spotted some reliability issues with actions and .formData(), where the promise never resolved. Though small reproductions dont actually recreate the issue. Something subtle with our streams implementation.
Looking into it and maybe we'll have it fully working by 0.7.3.
update: found what is blocking sveltekit actions from working:
const headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Set-Cookie", "cookies");
const entries = Array.from(headers);
expect(entries).toEqual([
["content-type", "application/json"],
["set-cookie", "cookies"],
]);
what bun is doing is duplicating the content-type header, meaning cookies never get set.
this took a very long time to narrow down haha
the set cookie pr will make dev server fully functional. there is a different issue that is tracked by #3943 but i htink we should keep this issue open until that is fixed as this a broader tracking issue.
we are close. i imagine this week / next release
did i say this week actually meant now after https://github.com/oven-sh/bun/pull/4052
@paperdave are there special considerations for running SvelteKit with Bun like changing the adapter or some other tweak? Forms are still hanging on me. Looks related to websockets. I'm running all the latest packages and the latest canary build on WSL2.
@gitblit I don't think the canary has been updated since this fix was added. You can see here under canary when it was updated last - some 22h ago. The only way you can test this now would be to build bun locally, which actually isn't that hard, or just try again tomorrow.
I'll admit I don't know exactly how the binaries are served. The README suggests canary is built on every push to main and I was assuming they are downloaded from Github artifacts and not from a Docker container, but that might not be a valid assumption.
@gitblit interesting, you might be right about that. In that case I wonder why the canary docker image isn't kept in sync.
Canary is compiled on every commit to main. Here is the most recent one for Linux x64 at the time of writing: https://github.com/oven-sh/bun/actions/runs/5794742061
The bun-linux-x64 one is the artifact which becomes the canary build of bun
The 0.8.0 canary is now running my SvelteKit app almost perfectly. The fix for hanging await formData mentioned on Twitter addresses the scenario I noted here. I will post the remaining issue I observe as a new ticket.
There is something going on here - sveltekit often freezes and doesn't manage to boot the server.
- https://github.com/oven-sh/bun/issues/4371#issuecomment-1695270779
For the development of bun run dev, I prefer to use a plugin like vite directly on vs code store because there is a bug
To build for production, you'll need to add the right SvelteKit adapter. Currently we recommend the
bun add -D svelte-adapter-bun.
Now, make the following changes to your svelte.config.js.
Let's see what the svelte summit tomorrow brings of announcements.