svelte-sonner icon indicating copy to clipboard operation
svelte-sonner copied to clipboard

Not working on SvelteKit 2 and Svelte 5

Open jramiroz98 opened this issue 1 year ago • 11 comments

I get the following errors until the imports are removed

Error when evaluating SSR module

CompileError: Expected a valid CSS identifier

loc: {
    line: 773,
    column: 39,
    file: '/path/to/Toaster.svelte'

jramiroz98 avatar Jan 01 '24 15:01 jramiroz98

We won't have full support for Svelte 5 until it is stable. Are you able to reproduce this with SvelteKit 2 and Svelte 4?

It sounds like a Svelte 5 issue considering its an error with compilation.

huntabyte avatar Jan 06 '24 04:01 huntabyte

Update on this, there have been multiple reports of this with not only svelte-sonner, but also https://github.com/huntabyte/vaul-svelte, so it's definitely an issue with the Svelte 5 compiler.

huntabyte avatar Jan 10 '24 14:01 huntabyte

Just came here to say I got this issue with Svelte5 and Sveltekit 2

The toast shows up but just never goes away and console has all these messages...

image

GimpMaster avatar Jan 16 '24 05:01 GimpMaster

Those are Svelte 5 issues which won't be officially supported until Svelte 5 is stable as it makes no sense to support something in alpha.

huntabyte avatar Jan 17 '24 16:01 huntabyte

That makes sense. Just wanted to report.

GimpMaster avatar Jan 17 '24 16:01 GimpMaster

I'm still getting a ERR_SVELTE_TOO_MANY_UPDATES error logged in the browser console on 5.0.0-next.69

pheuter avatar Mar 01 '24 13:03 pheuter

just incase others see this issue, but this was solved by updating svelte-5 to the latest version which is currently next.123 @pheuter @huntabyte. it should remove the 'too many updates' error :)

vexkiddy avatar May 06 '24 16:05 vexkiddy

thank you for the update @vexkiddy !

wobsoriano avatar May 06 '24 17:05 wobsoriano

Related to Svelte 5 and SvelteKit 2.0

How can I know when the Toaster component is mounted?

The <Toaster /> component is defined in +layout.ts.

I'm currently using the setTimeout workaround to ensure the toast is displayed correctly. Is there another approach to handle this, or is it a bug?

// +page.svelte
// This came from the server +page.server.ts
let { data } = $props();

let errors = $state(data.errors);

$effect(() => {
  if (errors) {
	  // setTimeout is used to prevent the toast from being displayed before the toast component is rendered
	  setTimeout(() => toast.error(errors[0].message, { duration: 5000 }), 100);
  }
});

edproton avatar Jun 20 '24 16:06 edproton

I have run into the same issue with toasts pre-toaster mount not being displayed. It would be great if any calls to toast() prior to Toaster being mounted would be cached and then run onMount

justinkwaugh avatar Jul 26 '24 12:07 justinkwaugh

Working for me in Svelte 5(199)/Sveltekit 2 w/ shadcn-svelte

https://github.com/user-attachments/assets/6e743b92-fbb8-4028-8ded-1eb3d8a07bf9

travisdmathis avatar Aug 09 '24 19:08 travisdmathis

I get that this is not supported but I still want to share my error using the latest SvelteKit and Svelte versions with shadcn-svelte as it is a bit weird.

It used to work and then suddenly stopped:


error when starting dev server:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".svelte" for /home/vdawg/dev/svelte-app/node_modules/.pnpm/[email protected][email protected]/node_modules/svelte-sonner/dist/Loader.svelte
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:218:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:244:36)
    at defaultLoad (node:internal/modules/esm/load:122:22)
    at async nextLoad (node:internal/modules/esm/hooks:748:22)
    at async nextLoad (node:internal/modules/esm/hooks:748:22)
    at async Hooks.load (node:internal/modules/esm/hooks:385:20)
    at async handleMessage (node:internal/modules/esm/worker:199:18)
 ELIFECYCLE  Command failed with exit code 1.

vdawg-git avatar Oct 11 '24 13:10 vdawg-git

I get that this is not supported but I still want to share my error using the latest SvelteKit and Svelte versions with shadcn-svelte as it is a bit weird.

It used to work and then suddenly stopped:

error when starting dev server:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".svelte" for /home/vdawg/dev/svelte-app/node_modules/.pnpm/[email protected][email protected]/node_modules/svelte-sonner/dist/Loader.svelte
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:218:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:244:36)
    at defaultLoad (node:internal/modules/esm/load:122:22)
    at async nextLoad (node:internal/modules/esm/hooks:748:22)
    at async nextLoad (node:internal/modules/esm/hooks:748:22)
    at async Hooks.load (node:internal/modules/esm/hooks:385:20)
    at async handleMessage (node:internal/modules/esm/worker:199:18)
 ELIFECYCLE  Command failed with exit code 1.

For anyone running into this issue, I've managed to fix it for now by including "svelte-sonner" in the optimizeDeps option in vite.config.ts. Like so:

export  default  defineConfig({
	plugins: [sveltekit()],
	optimizeDeps: {
		include: ['svelte-sonner']
	}
});

satanskitty avatar Oct 18 '24 10:10 satanskitty