Skip to content

Type Error on new Vite projects with svelte-ts project #1055

Closed
@trbernstein

Description

@trbernstein

Describe the bug

Starting a new Vite project and selecting svelte-ts template (by first selecting svelte and then TypeScript) results in an error, because code var in error.js is null.

Reproduction URL

https://github.com/vitejs/vite/tree/main/packages/create-vite/template-svelte-ts

Reproduction

  1. Start a new Vite project using npm create vite@latest
  2. Install dependencies in project folder with npm install
  3. Start dev server with npm run dev
  4. Observe error.

Logs

[vite] Internal server error: Cannot read properties of undefined (reading 'startsWith')
Plugin: vite-plugin-svelte
File: /***/src/App.svelte
    at couldBeFixedByCssPreprocessor (file://***/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/vite-plugin-svelte/src/utils/error.js:111:72)
    at enhanceCompileError (file://***/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/vite-plugin-svelte/src/utils/error.js:126:6)
    at compileSvelte (file:/***/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/vite-plugin-svelte/src/utils/compile.js:148:4)
    at async TransformPluginContext.transform (file:/***/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/vite-plugin-svelte/src/index.js:164:20)
    at async EnvironmentPluginContainer.transform (file:/***/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:47001:18)
    at async loadAndTransform (file:/***/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:40852:27)
    at async viteTransformMiddleware (file:/***/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:42296:24)

System Info

System:
    OS: macOS 15.2
    CPU: (24) arm64 Apple M2 Ultra
    Memory: 40.07 GB / 192.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - /opt/homebrew/bin/node
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 9.15.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Safari: 18.2
  npmPackages:
    @sveltejs/vite-plugin-svelte: ^5.0.2 => 5.0.2 
    svelte: ^5.14.2 => 5.14.2 
    vite: ^6.0.1 => 6.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageAwaiting triage by a project member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions