Skip to content

fix(css): resolve tsconfig paths in CSS and Sass @import#22775

Open
shulaoda wants to merge 1 commit into
mainfrom
06-26-fix_css_resolve_tsconfig_paths_in_css_and_sass_import
Open

fix(css): resolve tsconfig paths in CSS and Sass @import#22775
shulaoda wants to merge 1 commit into
mainfrom
06-26-fix_css_resolve_tsconfig_paths_in_css_and_sass_import

Conversation

@shulaoda

Copy link
Copy Markdown
Member

Description

close #22766

Since the oxc-resolver upgrade in Vite 8.1, resolve.tsconfigPaths stopped resolving paths aliases inside CSS @import and Sass @use, such as @import "@/styles/main.css".

oxc-resolver only applies a tsconfig's paths to a file that tsconfig owns through its files or include. For CSS @import, Vite passed a synthetic <dir>/* importer that has no file extension, so no tsconfig ever owns it and the paths aliases are skipped.

The fix passes the real importing file as the importer: CSS (postcss-import) uses the @import AtRule's source file, and Sass already uses context.containingUrl. Because tsconfig matches by extension, CSS/Sass files must be declared explicitly to receive paths, for example include: ["src", "src/**/*.css", "src/**/*.scss"]. This is documented under resolve.tsconfigPaths.

Less is not supported: its plugin API only exposes the importer's directory, not the file, so Vite cannot tell the resolver which tsconfig owns it. Use a relative path or resolve.alias for @import in Less. This is documented and locked in by a negative test.

playground/resolve-tsconfig-paths gains CSS @import and Sass @use cases that resolve via paths, plus a Less case asserting the alias stays unresolved.

Additional

I looked into supporting Less by overriding getPath in its file-manager plugin so the importer's file (not just its directory) is exposed to Vite, but that repurposes a method Less relies on internally for directory derivation and is too hacky, so Less is left unsupported for now.

@shulaoda shulaoda force-pushed the 06-26-fix_css_resolve_tsconfig_paths_in_css_and_sass_import branch from 0b78d2b to 72e7617 Compare June 25, 2026 16:44
@shulaoda shulaoda force-pushed the 06-26-fix_css_resolve_tsconfig_paths_in_css_and_sass_import branch from 72e7617 to 4ea8cd2 Compare June 25, 2026 22:10
@shulaoda shulaoda marked this pull request as ready for review June 25, 2026 22:11
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

Successfully merging this pull request may close these issues.

Vite 8.1 doesn't resolve tsconfigPaths in CSS @import directives

1 participant