This repository reproduces the issue described in here.
It’s a pnpm monorepo created with npx sv create my-app and slightly adjusted.
The repo contains two packages:
@web/app — the SvelteKit application (the one we build).@web/utils — a utility package that exports plain TypeScript files.Build command (from the monorepo root):
pnpm --filter @web/app build
@web/utils exports two functions from index.ts:
index.tstemp.tsWhen building @web/app as-is, the build fails because $lib/temp.js from @web/utils is incorrectly resolved as <...>/packages/app/src/lib/temp.js. In other words, $lib paths are always resolved relative to the SvelteKit app (@web/app), instead of the correct package where the file actually lives.
If we add vite-tsconfig-paths plugin, it should correctly resolve aliases based on each package’s tsconfig.However, it does not work until we manually remove the $lib alias that SvelteKit injects into the Vite config.
The @sveltejs/kit/vite plugin always forces $lib into Vite’s resolve.alias. According to Vite’s docs, resolve.alias is passed to Rollup’s alias plugin. Rollup’s alias plugin performs a simple string replacement, without considering tsconfig. Because this happens before vite-tsconfig-paths runs, all $lib imports are already replaced with incorrect paths.