Skip to content

Fix Windows CI: normalize absolute paths in SCSS @use/@import/@forward for Sass compatibility#85

Merged
Simon-He95 merged 3 commits into
mainfrom
copilot/fix-sass-import-error
Mar 26, 2026
Merged

Fix Windows CI: normalize absolute paths in SCSS @use/@import/@forward for Sass compatibility#85
Simon-He95 merged 3 commits into
mainfrom
copilot/fix-sass-import-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Dart Sass misinterprets Windows drive letters (C:/) as URL schemes in @use/@import/@forward directives, causing "Can't find stylesheet to import" on Windows CI. Same root cause as Simon-He95/transformToUnoCSS#68. Aligned with fix patterns from transformToUnoCSS PR #67, #69, and #70.

  • src/sassCompiler.ts: Before compilation, detect absolute Windows paths in SCSS import directives, extract the parent directory into loadPaths, and rewrite to just the basename
// @use "C:/Users/RUNNER~1/.../styles/tokens" as *;  ← Sass sees "C:" as URL scheme
// becomes:
// @use "tokens" as *;  ← loadPaths now includes the parent directory
const winAbsPathRegex = /@(use|import|forward)\s+(['"])([A-Za-z]:[/\\][^'"]+)\2/g
result = result.replace(winAbsPathRegex, (match, kw, quote, absPath) => {
  const dir = path.dirname(absPath.replace(/\//g, path.sep))
  if (!compileOptions.loadPaths.includes(dir))
    compileOptions.loadPaths.push(dir)
  return `@${kw} ${quote}${path.basename(absPath.replace(/\//g, path.sep))}${quote}`
})
  • src/sassCompiler.ts: Return original CSS instead of undefined on Sass compilation errors, so that transformVue can still process the style block even when compilation fails (aligned with transformToUnoCSS PR chore(deps): update dependency stylus to v0.64.0 #70)

  • test/sassCompiler.test.ts: Updated error case test expectation to match the new behavior of returning original CSS on failure

Original prompt

This section details on the original issue you should resolve

<issue_title>bug</issue_title>
<issue_description>这个issue:https://github.com/Simon-He95/transformToUnoCSS/pull/69#issuecomment-4132445310,的问题还是存在
下面是最新的ci的报错

RUN v3.2.4 D:/a/transformToTailwindcss/transformToTailwindcss

✓ test/classCollectorComplex.test.ts (16 tests) 22ms
✓ test/browserCompatibility.test.ts (8 tests) 518ms
✓ Browser environment compatibility > transformCss environment handling > should import transformCss without errors in Node.js environment 460ms
stdout | test/sassCompiler.test.ts > sassCompiler > should handle error cases gracefully
[transform-to-unocss] Compiling SCSS file: D:\a\transformToTailwindcss\transformToTailwindcss\test\demo\sass\error-test.scss

stderr | test/sassCompiler.test.ts > sassCompiler > should handle error cases gracefully
Error:
transform-to-unocss(sassCompiler) Can't find stylesheet to import.

2 │ @use './non-existent-file';
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^

C:\Users\runneradmin\AppData\Local\Temp\transform-to-tailwindcss-1RrWOn\input.scss 2:7 root stylesheet

stderr | test/sassCompiler.test.ts > compilerCss file:// URL handling > should handle file:// URLs gracefully (may fail but should not crash)
stdout | test/sassCompiler.test.ts > compilerCss file:// URL handling > should handle file:// URLs gracefully (may fail but should not crash)
Error:
Processing CSS with file:// URL...
transform-to-unocss(sassCompiler) Can't find stylesheet to import.


2 │ @use 'file:///some/absolute/path/to/styles.scss';
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

C:\Users\runneradmin\AppData\Local\Temp\transform-to-tailwindcss-vt8aAw\input.scss 2:7 root stylesheet

✓ test/sassCompiler.test.ts (15 tests) 675ms
✓ sassCompiler > should compile basic SCSS 437ms
✓ test/classCollector.test.ts (11 tests) 23ms
stdout | ClassCollector.generateSafelistFile (D:\a\transformToTailwindcss\transformToTailwindcss\src\classCollector.ts:331:15)
[transform-to-tailwindcss] Generated safelist file: ./safelist-classes.js

stdout | ClassCollector.generateSafelistFile (D:\a\transformToTailwindcss\transformToTailwindcss\src\classCollector.ts:334:15)
[transform-to-tailwindcss] Collected 2 unique classes

stderr | test/transformCode.test.ts > transformCode > transformCode: all

  • color: $brand-color;
  • }</style>

❯ test/transformAstro.test.ts:59:20
57| })
58|
59| expect(result).toContain('text-red')
| ^
60| expect(result).not.toContain('$brand-color')
61|

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Test Files 1 failed | 10 passed (11)
Tests 1 failed | 81 passed (82)
Start at 09:28:10
Duration 5.88s (transform 480ms, setup 0ms, collect 5.26s, tests 4.61s, environment 4ms, prepare 2.07s)

Error: AssertionError: expected '---\nexport const prerender = true;\n…' to contain 'text-red'

  • Expected
  • Received
  • text-red

  • export const prerender = true;

  • hi

  • <style>@use "C:/Users/RUNNER~1/AppData/Local/Temp/transform-to-tailwindcss-astro-JMVbIb/src/styles/tokens" as *;
  • .title {
  • color: $brand-color;
  • }</style>

❯ test/transformAstro.test.ts:59:20

 ELIFECYCLE  Test failed. See above for more details.
Error: Process completed with exit code 1.</issue_description>

Comments on the Issue (you are @copilot in this section)


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 26, 2026

Deploy Preview for to-tailwindcss canceled.

Name Link
🔨 Latest commit 79cce7d
🔍 Latest deploy log https://app.netlify.com/projects/to-tailwindcss/deploys/69c501a4d7b15000089f1a21

@Simon-He95
Copy link
Copy Markdown
Owner

@copilot 你应该关注一下下面几个pr的修复方案:

Simon-He95/transformToUnoCSS#70
Simon-He95/transformToUnoCSS#69
Simon-He95/transformToUnoCSS#67

…or Sass compatibility

On Windows, drive letters like C:/ in @use paths are misinterpreted as
URL schemes by Dart Sass, causing 'Can't find stylesheet to import' errors.
Extract the directory into loadPaths and rewrite to just the module name.

Co-authored-by: Simon-He95 <57086651+Simon-He95@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Simon-He95/transformToTailwindcss/sessions/3d36196a-6917-47a4-88cd-ac5d5e21ffa3
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 26, 2026

Deploying transformtotailwindcss with  Cloudflare Pages  Cloudflare Pages

Latest commit: 79cce7d
Status: ✅  Deploy successful!
Preview URL: https://def16b4b.transformtotailwindcss.pages.dev
Branch Preview URL: https://copilot-fix-sass-import-erro.transformtotailwindcss.pages.dev

View logs

Copilot AI changed the title [WIP] Fix issue with SCSS file import in sassCompiler Fix Windows CI: normalize absolute paths in SCSS @use/@import/@forward for Sass compatibility Mar 26, 2026
Copilot AI requested a review from Simon-He95 March 26, 2026 09:46
Align error handling with transformToUnoCSS PR #70: when Sass compilation
fails, return the original CSS input instead of undefined so that
transformVue can still process the style block.

Co-authored-by: Simon-He95 <57086651+Simon-He95@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Simon-He95/transformToTailwindcss/sessions/8c2955bd-691e-4e84-b24b-e78cc31b49ad
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 26, 2026

@copilot 你应该关注一下下面几个pr的修复方案:

Simon-He95/transformToUnoCSS#70
...

Reviewed all three PRs and applied the same patterns:

  1. PR chore(deps): update dependency @iconify/json to v2.2.401 #67 (.gitattributes eol=lf) — already present in this repo ✓
  2. PR chore(deps): update dependency vue-use-monaco to ^0.0.33 #69/chore(deps): update dependency stylus to v0.64.0 #70 (Windows absolute path handling) — already applied in commit 1befa94 using the loadPaths approach to avoid drive-letter-as-URL-scheme issue
  3. PR chore(deps): update dependency stylus to v0.64.0 #70 (error handler returns original CSS) — applied in commit 79cce7d. Changed return undefined to return css in sassCompiler's error handler so that transformVue can still process the style block even if Sass compilation fails. Updated the corresponding test expectation.

@Simon-He95 Simon-He95 marked this pull request as ready for review March 26, 2026 10:27
@Simon-He95 Simon-He95 merged commit 89b61c0 into main Mar 26, 2026
6 checks passed
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.

bug

2 participants