workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

feature request: vite plugin with sveltekit

Open domoritz opened this issue 7 months ago • 6 comments

Which Cloudflare product(s) does this pertain to?

Vite Plugin

What versions & operating system are you using?

macOS

Please provide a link to a minimal reproduction

No response

Describe the Bug

I am trying to access a D1 database defined in my wrangler.jsonc. The documentation for the svelte plugin make it seem as though it should just work but I don't see a database in my hooks.server.ts.

import type { Handle } from "@sveltejs/kit";
import { DB } from '$env/static/private';

export const handle: Handle = async ({ event, resolve }) => {
  // all undefined
  console.log(process.env.DB, import.meta.env.DB, DB);
}

svelte config

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://svelte.dev/docs/kit/integrations
	// for more information about preprocessors
	preprocess: vitePreprocess(),
};

export default config;

vite config

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { cloudflare } from "@cloudflare/vite-plugin";

export default defineConfig({
	plugins: [sveltekit(), cloudflare()]
});

Please provide any relevant error logs

No response

domoritz avatar Apr 13 '25 16:04 domoritz

It works with the adapter but I thought the idea of the Vite plugin is that I don't need an adapter anymore.

import adapter from "@sveltejs/adapter-cloudflare";
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://svelte.dev/docs/kit/integrations
	// for more information about preprocessors
	preprocess: vitePreprocess(),

	kit: {
		adapter: adapter()
	}
};

export default config;

domoritz avatar Apr 13 '25 16:04 domoritz

Hey the vite plugin does not work with sveltekit yet, but we're working on it with the svelte team :)

emily-shen avatar Apr 13 '25 23:04 emily-shen

Ah ok, thanks for clarifying. I'll use the adapter for now then.

domoritz avatar Apr 13 '25 23:04 domoritz

Hey the vite plugin does not work with sveltekit yet, but we're working on it with the svelte team :)

Thanks for the info, would you be able to hazard an ETA?

fredguest avatar Apr 23 '25 00:04 fredguest

My day would be made if this ships <3

didier avatar May 03 '25 23:05 didier

Using the adapter for development introduces a delay every time we save the files for rebuilding. It would be great if the vite plugin works so we get HMR.

romeupalos avatar May 17 '25 04:05 romeupalos

I would love to see support, because it currently makes stuff very difficult to use multiple workers.

umgefahren avatar Aug 28 '25 09:08 umgefahren

Still waiting on this :(

zemjr avatar Nov 25 '25 03:11 zemjr

@zemjr there's quite a lot of places this is talked about - not really a single place to track it but here's the latest update AFAIK

we’re waiting until SvelteKit 3 before we move to the environment API

Originally posted in https://github.com/sveltejs/kit/issues/14008#issuecomment-3567568069

philippviereck avatar Nov 25 '25 07:11 philippviereck