Skip to content

svelte-preprocess may silently fail to auto-resolve tsconfig #667

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

Open
7nik opened this issue Apr 17, 2025 · 3 comments
Open

svelte-preprocess may silently fail to auto-resolve tsconfig #667

7nik opened this issue Apr 17, 2025 · 3 comments

Comments

@7nik
Copy link

7nik commented Apr 17, 2025

From sveltejs/svelte#15782

If tsconfig.json does not contain compilerOptions and instead references other tsconfigs, svelte-preprocess fails to get the actual TS configs. In particular, it results in the fallbacked target ES2015, where object resting isn't supported yet (it was added in ES2018), and the following component fails to compile:

<script lang="ts">
  let { foo = $bindable("foo"), ...rest } = $props();
</script>

{foo} {Object.keys(rest)}
[plugin:vite-plugin-svelte] src/App.svelte:12:27 `$bindable()` can only be used inside a `$props()` declaration
https://svelte.dev/e/bindable_invalid_location

src/App.svelte:12:27

10 |      return t;
 11 |  };
 12 |  let _a = $props(), { foo = $bindable("foo") } = _a, rest = __rest(_a, ["foo"]);
                                                  ^
 13 |  </script>
 14 |

To Reproduce

  1. Create a project via npm create vite, select Svelte and Typescript.
  2. Install svelte-preprocess npm i svelte-preprocess and apply it vite.config.ts
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { sveltePreprocess } from 'svelte-preprocess';

// https://vite.dev/config/
export default defineConfig({
  plugins: [svelte({
    preprocess: sveltePreprocess()
  })],
})
  1. Add the aforementioned component.
  2. Run the project.

Expected behavior
The component is successfully compiled.

Information about your project:

  • svelte-preprocess version 6.0.3
@dummdidumm
Copy link
Member

Probably makes sense to use a more recent target by default

@janosh
Copy link

janosh commented Jun 6, 2025

sounds like something that'll be fixed in svelte-preprocess? is there a workaround packages can apply so users don't encounter this error? asking for janosh/svelte-multiselect#305

@7nik
Copy link
Author

7nik commented Jun 6, 2025

I looked into this. I thought that the tsconfig should be just extended with referenced ones, but after reading the docs, I understood that references allows running TS on files (subprojects) with independent tsconfigs simultaneously and in within a single process. That means that svelte-preprocess should find and apply tsconfig matching the current file.

So, maybe for now it would be easier to just emit a warning that svelte-preprocess failed to auto-resolve tsconfig or the resolved tsconfig doesn't contain compilerOptions, so the user should manually specify path to it.

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

3 participants