Skip to content

fix(css): resolve sass partial package imports from file urls#22505

Closed
cjc0013 wants to merge 1 commit into
vitejs:mainfrom
cjc0013:cjc/22294-sass-windows-export-path
Closed

fix(css): resolve sass partial package imports from file urls#22505
cjc0013 wants to merge 1 commit into
vitejs:mainfrom
cjc0013:cjc/22294-sass-windows-export-path

Conversation

@cjc0013

@cjc0013 cjc0013 commented May 23, 2026

Copy link
Copy Markdown

Fixes #22294.

When Sass uses the modern importer API, it can call canonicalize with a file:// URL before the raw specifier. For imports like @vite-sass-bug/example/styles/mixins, that first URL looks like a non-existent relative file under the importer directory. Vite currently tries that path and then lets Sass fall through to package resolution, which fails on Windows for package-exported partials because the partial subpath is checked with a backslash.

This PR keeps the existing relative-path attempt first. If that misses, it recovers the bare package specifier from the file URL and retries through Vite's Sass resolver. For Sass partials, it also retries the underscore-prefixed partial form so package exports like ./styles/*: { sass: ./dist/styles/*.scss } can resolve styles/mixins to dist/styles/_mixins.scss on Windows.

Added a regression fixture that simulates the Sass file URL canonicalization path for a package-exported partial.

Validation:

  • git diff --check
  • pnpm dlx oxfmt@0.51.0 --check packages/vite/src/node/plugins/css.ts packages/vite/src/node/__tests__/plugins/css.spec.ts
  • Verified the reporter's repro on Windows: before the patch, vite build fails with ./styles\\_mixins is not exported; after applying the same resolver change to the installed Vite package, the original @use '@vite-sass-bug/example/styles/mixins' build passes.

I couldn't complete a full local Vite workspace install on this machine because the available D: drive is exFAT and pnpm workspace symlinks fail there, so I kept validation to formatting, diff checks, and the focused Windows repro.

@cjc0013 cjc0013 force-pushed the cjc/22294-sass-windows-export-path branch from 4aec5de to 1369f04 Compare May 23, 2026 20:00
@cjc0013

cjc0013 commented May 23, 2026

Copy link
Copy Markdown
Author

Build & Test is now passing on Linux/macOS/Windows after the latest push. The remaining red check is zizmor; from the log it fails while auditing an existing workflow (.github/workflows/issue-close-require.yml) because GitHub returns 403 while listing tags for actions-cool/issues-helper. This PR doesn't touch workflows, so that looks unrelated/transient.

@sapphi-red

Copy link
Copy Markdown
Member

This should be fixed in viteResolvePlugin exported from rolldown/experimental.

@sapphi-red sapphi-red closed this May 25, 2026
sapphi-red added a commit to rolldown/rolldown that referenced this pull request Jun 5, 2026
…#9546)

## Summary
- keep retry-with-prefix specifiers slash-separated for bare deep
imports so package exports see keys like `./styles/_mixins` on Windows
- preserve the existing path-based prefix behavior for relative and
absolute specifiers
- add a `viteResolvePlugin` fixture that resolves a Sass partial through
package `exports`

## Context
This follows the maintainer note in vitejs/vite#22505 that the fix
belongs in `viteResolvePlugin` exported from `rolldown/experimental`.

Refs vitejs/vite#22294 and vitejs/vite#22505.

## Validation
- `git diff --check`
- Not run locally: Rust/fixture test suites, because `cargo`, `pnpm`,
and `just` are not available in this local environment.

---------

Co-authored-by: cjc0013 <cjc0013@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
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.

sass exports not working on windows

2 participants