bun icon indicating copy to clipboard operation
bun copied to clipboard

Create Sveltekit Apps using Bun

Open niiwade opened this issue 3 years ago • 5 comments
trafficstars

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 avatar Jul 11 '22 22:07 niiwade

@niiwade Would you like to create a PR for this?

FinnRG avatar Jul 11 '22 22:07 FinnRG

yes sure

niiwade avatar Jul 11 '22 22:07 niiwade

note that there is a community adapter here you can maybe crib from https://github.com/gornostay25/svelte-adapter-bun

swyxio avatar Jul 11 '22 22:07 swyxio

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

niiwade avatar Jul 11 '22 23:07 niiwade

Any good news on SvelteKit + bun runtime?

This would be a great framework to get first class support for in bun.

image

ryanrussell avatar Jul 30 '22 21:07 ryanrussell

Status on SvelteKit:

  • It depends on worker_threads, though not much of it. Just parentPort and new Worker, and passing env data.
  • Since we do not export anything in worker_threads, it causes vite to crash loading the config file.

paperclover avatar Jul 22 '23 01:07 paperclover

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.

kansson avatar Aug 03 '23 03:08 kansson

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!!

image

gitblit avatar Aug 03 '23 13:08 gitblit

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.

paperclover avatar Aug 04 '23 00:08 paperclover

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

paperclover avatar Aug 05 '23 02:08 paperclover

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

paperclover avatar Aug 07 '23 22:08 paperclover

did i say this week actually meant now after https://github.com/oven-sh/bun/pull/4052

paperclover avatar Aug 08 '23 06:08 paperclover

@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.

image

gitblit avatar Aug 08 '23 12:08 gitblit

@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.

birkskyum avatar Aug 08 '23 12:08 birkskyum

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 avatar Aug 08 '23 12:08 gitblit

@gitblit interesting, you might be right about that. In that case I wonder why the canary docker image isn't kept in sync.

birkskyum avatar Aug 08 '23 13:08 birkskyum

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

Jarred-Sumner avatar Aug 08 '23 13:08 Jarred-Sumner

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.

gitblit avatar Aug 24 '23 04:08 gitblit

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

birkskyum avatar Aug 28 '23 08:08 birkskyum

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

Tyjust31 avatar Nov 10 '23 19:11 Tyjust31

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.

Tyjust31 avatar Nov 10 '23 19:11 Tyjust31

Let's see what the svelte summit tomorrow brings of announcements.

birkskyum avatar Nov 10 '23 20:11 birkskyum