vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.17k stars 5.91k forks source link

Vite is treating TypeScript code in .svelte files as JavaScript (ignoring lang="ts") #17445

Closed uhidontkno closed 1 month ago

uhidontkno commented 1 month ago

Describe the bug

I am trying to use Shadcn-Svelte with my Svelte app and when trying to use components, I get errors from vite that seem like vite is interpreting Svelte scripts as JavaScript files, completely ignoring the lang="ts". My configuration files are correct, as they are unmodified from the svelte starter template.

I get errors along the lines of

[plugin:vite-plugin-svelte] .../frontend/src/lib/components/ui/input/input.svelte:2:13 Unexpected token
.../frontend/src/lib/components/ui/input/input.svelte:2:13
1 |  <script lang="ts">
 2 |    import type { HTMLInputAttributes } from "svelte/elements";
                    ^
 3 |    import type { InputEvents } from "./index.ts";
 4 |    import { cn } from "$lib/utils.ts";

Reproduction

bunx create svelte -> bunx shadcn-svelte init -> bunx shadcn-svelte add button

Steps to reproduce

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (4) x64 Intel(R) Core(TM) i7-4610M CPU @ 3.00GHz
    Memory: 6.58 GB / 15.53 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 22.2.0 - ~/.nvm/versions/node/v22.2.0/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v22.2.0/bin/npm
    bun: 1.1.10 - ~/.bun/bin/bun
  npmPackages:
    vite: ^5.2.12 => 5.2.12

Used Package Manager

bun

Logs

No response

Validations

bluwy commented 1 month ago

Duplicate of https://github.com/sveltejs/vite-plugin-svelte/issues/928