svelte: Svelte 5: runes-mode compiler validation errors throw "undefined"

Describe the bug

I just noticed that any plain on…="…" attributes (e.g. onclick="…") in component html will break the build if there are still deprecated on:… (e.g. on:click="…") attributes present in the same file, but with an obscure error message:

error during build:
undefined

A fix of course is to only use exclusively the new or deprecated syntax – but I guess there is some compiler problem or at least an opportunity for a better error message 😃

This might be a fix for #13883.

Reproduction

$ npm create vite@latest
✔ Select a framework: › Svelte
✔ Select a variant: › JavaScript

$ npm install
$ npm run build

vite v5.4.10 building for production...
…
✓ built in 174ms

# Add any on-attribute, e.g.
$ vi src/App.svelte
<div onclick={() => console.log('hi')}>

$ npm run build

vite v5.4.10 building for production...
✓ 51 modules transformed.
x Build failed in 84ms
error during build:
undefined

Logs

see reproduction

System Info

Node: 22.8.0
npm: 10.8.2

@sveltejs/vite-plugin-svelte: 4.0.0
svelte: 5.1.1
vite: 5.4.10

Severity

annoyance

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Commenting out every import from lucide-svelte shows the same error. Since this isn’t really related to the original issue anymore i will open a new one

Edit for anyone stumbling onto this: the error was in the mdsvex preprocessor configuration, in svelte.config.js:

preprocess: [
  mdsvex({
    extensions: ['.svx'], // ['.svelte', '.svx'] -- .svelte extension was causing the error! removing it fixed it :)
  }),
  sveltePreprocess(...)
]

This is more widespread, thanks @zuckschwerdt for the throw wrapping trick.

It’s also happening when there’s a <tr> directly inside a <table>: image

Whereas it should be: image

Whilst we’re at it, the difficult to find breaking changes area (especially since this works in dev mode) lists it under “Breaking Changes in runes mode”, which we’re not in. Shouldn’t this be under “Other breaking changes”.

https://svelte.dev/docs/svelte/v5-migration-guide#Breaking-changes-in-runes-mode-HTML-structure-is-stricter

This should probably throw an error in dev also.

Install the latest version of svelte and you should be getting more descriptive errors during build

For me InternalCompileError i.e. CompileDiagnostic can’t be thrown. If I wrap throw new InternalCompileError(…) as throw new Error(new InternalCompileError(…)) it seems to somewhat work.