sveltejs / vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
MIT License
817 stars 99 forks source link

TS doesn't compile #900

Closed JonathonRP closed 1 month ago

JonathonRP commented 1 month ago

Describe the bug

upgrading sveltekit project to use latest vite-plugin-svelte ts files do not compile

Reproduction URL

https://github.com/JonathonRP/Finanzen/tree/dev

Reproduction

run repo locally, and get build errors

Error when evaluating SSR module /src/lib/components/index.ts: failed to import "/src/lib/components/Form.svelte"
|- CompileError: Unexpected token `}`. Did you mean `}` or `{"}"}`?
    at e (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/errors.js:56:8)
    at Module.js_parse_error (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/errors.js:909:2)
    at Parser.acorn_error (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/phases/1-parse/index.js:161:5)
    at read_script (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/phases/1-parse/read/script.js:54:10)
    at tag (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/phases/1-parse/state/element.js:296:20)
    at new Parser (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/phases/1-parse/index.js:87:12)
    at parse (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/phases/1-parse/index.js:311:17)
    at Module.compile (file:///workspaces/Finanzen/node_modules/.pnpm/svelte@5.0.0-next.126/node_modules/svelte/src/compiler/index.js:26:16)
    at compileSvelte (file:///workspaces/Finanzen/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@4.0.0-next.0_svelte@5.0.0-next.126_vite@5.2.11/node_modules/@sveltejs/vite-plugin-svelte/src/utils/compile.js:136:22)
    at async TransformContext.transform (file:///workspaces/Finanzen/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@4.0.0-next.0_svelte@5.0.0-next.126_vite@5.2.11/node_modules/@sveltejs/vite-plugin-svelte/src/index.js:148:20)

image

Logs

No response

System Info

wsl, unbuntu
dominikg commented 1 month ago

the same error happens on the svelte5 playground

one of the breaking changes in vite-plugin-svelte@4 is that vitePreprocess no longer preprocesses typescript by default as svelte5 parser is supposed to understand it natively. As a workaround you can try to change your svelte config to use vitePreprocess({script: true}) to reenable it and see if it works then.

The initializer for validate seems what breaks it, are you sure that <typeof errors> is the right way to describe this?

It would be great if you could provide a minimal reproduction of the syntax you expect to work and demonstrate how it works in svelte4 and svelte5 with preprocessing ts but not in svelte5 without preprocessing ts.

Thanks

dominikg commented 1 month ago

You can also change to use {} as typeof errors for the type assertion, it looks like that works

JonathonRP commented 1 month ago

@dominikg you can close this apparently it's a known issue with svelte 5 TS that doesn't work but as cast works and it's good enough for me. I had made another but report in svelte repo.

dominikg commented 1 month ago

Next time please link the issue in the original report. I spent time analyzing this that i could have spent improving something else for everyone.

https://github.com/sveltejs/svelte/issues/11543