carbon-design-system / carbon-preprocess-svelte

Svelte preprocessors for the Carbon Design System
Apache License 2.0
68 stars 6 forks source link

Compatibility issues with Svelte 5 #61

Closed Ameobea closed 4 months ago

Ameobea commented 4 months ago

Although Svelte 5 is not yet released, it's in active development and preview and I thought it might be useful to get an early signal on this.

I set up a new project with create-svelte and chose the "Svelte 5 Preview" option during setup. I then installed carbon-components-svelte and carbon-preprocess-svelte.

After updating my svelte.config.js with the change specified in the README, I saw this error in the console:

6:59:46 PM [vite] Pre-transform error: Error while preprocessing /home/casey/osu-embeddings/frontend/.svelte-kit/generated/root.svelte - 'svelte/compiler' no longer exports a `walk` utility — please import it directly from 'estree-walker' instead
6:59:46 PM [vite] Error when evaluating SSR module /.svelte-kit/generated/root.js: failed to import "/.svelte-kit/generated/root.svelte"
|- Error: Error while preprocessing /home/casey/osu-embeddings/frontend/.svelte-kit/generated/root.svelte - 'svelte/compiler' no longer exports a `walk` utility — please import it directly from 'estree-walker' instead
    at e.walk (/home/casey/osu-embeddings/frontend/node_modules/svelte/compiler/index.js:1:676168)
    at script (/home/casey/osu-embeddings/frontend/node_modules/carbon-preprocess-svelte/dist/preprocessors/optimize-imports.js:32:33)
    at process_single_tag (file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/index.js:280:27)
    at file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/replace_in_code.js:30:4
    at String.replace (<anonymous>)
    at calculate_replacements (file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/replace_in_code.js:28:9)
    at replace_in_code (file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/replace_in_code.js:69:29)
    at process_tag (file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/index.js:297:32)
    at Module.preprocess (file:///home/casey/osu-embeddings/frontend/node_modules/svelte/src/compiler/preprocess/index.js:357:31)
    at async compileSvelte (file:///home/casey/osu-embeddings/frontend/node_modules/@sveltejs/vite-plugin-svelte/src/utils/compile.js:89:20)

It looks like these imports:

import { parse, walk } from "svelte/compiler";

Will need to be updated to work with Svelte v5. I'm not sure if there are other compat issues as well beyond these.

Anyway, this isn't a big problem right now because Svelte 5 is still not yet officially released - but yeah I wanted to give a heads up!

metonym commented 4 months ago

Thank you for flagging this!

This is unfortunate although I suppose that's to be expected with the preprocess-related stuff (where breaking changes can happen at any time).

I'll explore options to see if I can make this compatible with Svelte 5.

metonym commented 4 months ago

I've released v0.11.3 which now uses walk from estree-walker directly (the official recommended solution). This approach allows Svelte 5 compatibility without needing to have carbon-preprocess-svelte depend on a specific version of Svelte.

Ameobea commented 4 months ago

That's terrific! Thanks very much for doing that and for your excellent stewardship of this project.