Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with external Svelte 5 components #655

Open
legowhales opened this issue Sep 13, 2024 · 6 comments
Open

Error with external Svelte 5 components #655

legowhales opened this issue Sep 13, 2024 · 6 comments

Comments

@legowhales
Copy link

Describe the bug

Using svelte-preprocess with Svelte 5 and importing a Svelte 5 component from an npm package triggers an error:
'p' has already been declared

Detailed error with a random package

Same error occurs with bits-ui@next, svelte-clerk...

✘ [ERROR] node_modules/ui-ingredients/dist/select/item-text.svelte:9:24 `p` has already been declared [plugin vite-plugin-svelte:optimize-svelte]

    node_modules/ui-ingredients/dist/select/item-text.svelte:9:24:
      9 │        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.l...
        ╵                         ^

  The plugin "vite-plugin-svelte:optimize-svelte" was triggered by this import

To Reproduce

I made a simple example here:

https://stackblitz.com/edit/sveltejs-kit-template-default-u71xqf?file=svelte.config.js

Is there a simple way to make it work?
Thank's for your help.

@dummdidumm
Copy link
Member

The problem is that svelte-preprocess searches for a tsconfig.json but doesn't find one and therefore falls back to an old target version which includes a down-level-transpilation of the ...rest syntax. That subsequently messes with Vite for some reason.

You can fix this by changing your jsconfig.json to a tsconfig.json.

We should probably also search for a jsconfig.json in the TypeScript preprocessor, if we don't find a tsconfig.json - even if it's a bit weird because why would someone have a jsconfig.json if they're using a TS preprocessor.

@legowhales
Copy link
Author

Hum... well in my case I already have a tsconfig.json. But the sveltekit project is in a subfolder (in a monorepo without a tsconfig at the root level). Would that trigger the same issue as well?

I tried adding a tsconfig.json at the root of the repo, but I get the same issue.

@dummdidumm
Copy link
Member

Does the SvelteKit project in which you have this error have a tsconfig.json? What happens if you set the tsconfigDirectory option?

@legowhales
Copy link
Author

Yes it has.
I tried to set isconfigDirectory, but nothing changes. I updated the stackblitz example to show you the issue: https://stackblitz.com/edit/sveltejs-kit-template-default-u71xqf?file=app%2Ftsconfig.json

@dummdidumm
Copy link
Member

What error should I be expecting in that stackblitz example? The image loads up and there's no error in the Stackblitz console.

@legowhales
Copy link
Author

legowhales commented Sep 26, 2024

Oh yeah you are right. I made other tests since the last comment. What you where seeing is when we use the preprocessor from @sveltejs/vite-plugin-svelte. I just modified back to using svelte-preprocess, you should see the error now.

Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants