You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the <script lang="ts"> has a long generics attribute that causes prettier to break it into multiple lines, imports with a .js extension that should resolve to a TS file are no longer working.
❯ pnpm build
>[email protected] build /tmp/svelte-ts-import
> vite build
vite v5.4.11 building for production...
✓ 15 modules transformed.
x Build failed in 70ms
error during build:
Could not resolve "./lib/test.js" from "src/App.svelte"
file: /tmp/svelte-ts-import/src/App.svelte
at getRollupError (file:///tmp/svelte-ts-import/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
at error (file:///tmp/svelte-ts-import/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:392:42)
at ModuleLoader.handleInvalidResolvedId (file:///tmp/svelte-ts-import/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:20085:24)
at file:///tmp/svelte-ts-import/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:20045:26
ELIFECYCLE Command failed with exit code 1.
OK, I found the problem is caused by vite-plugin-svelte. It uses a similar regex as the compiler to extract the script tag's language. But it has this as an edge case.
Fix:
Describe the bug
If the
<script lang="ts">
has a longgenerics
attribute that causes prettier to break it into multiple lines, imports with a.js
extension that should resolve to a TS file are no longer working.If you change the import to
'./lib/test.ts'
or'./lib/test'
it works again.If you add a space after
<script
it also works again.Reproduction
Repo: https://github.com/fehnomenal/svelte-ts-import
This is the vite@latest svelte template stripped of all unneeded stuff.
The second commit (fehnomenal/svelte-ts-import@91e042f) gives the diff as an example.
Logs
System Info
System: OS: Linux 6.6 cpe:/o:nixos:nixos:24.11 24.11 (Vicuna) CPU: (16) x64 AMD Ryzen 7 7840HS w/ Radeon 780M Graphics Memory: 9.77 GB / 60.64 GB Container: Yes Shell: 0.99.1 - /run/current-system/sw/bin/nu Binaries: Node: 23.1.0 - /etc/profiles/per-user/andi/bin/node npm: 10.9.0 - /etc/profiles/per-user/andi/bin/npm pnpm: 9.14.1 - /etc/profiles/per-user/andi/bin/pnpm bun: 1.1.31 - /etc/profiles/per-user/andi/bin/bun Browsers: Chromium: 130.0.6723.91 npmPackages: svelte: 5.2.7 => 5.2.7
Severity
annoyance
The text was updated successfully, but these errors were encountered: