Browse Source

fix: resolve Windows "Can't resolve tailwindcss" error (#11747)

On Windows, turbopack/utoopack passes a doubled relative path as the
PostCSS `from` option (e.g. `./Desktop/demo/project/src/file.css`
instead of `./src/file.css`), causing `@tailwindcss/postcss` to resolve
`@import "tailwindcss"` from a non-existent directory.

Add a lightweight PostCSS plugin that detects the broken path (file does
not exist) and corrects it before `@tailwindcss/postcss` reads it.
On macOS/Linux the plugin is a no-op.

Also fix `@source "./src"` → `@source "."` in `src/tailwind.css`:
`@source` paths are relative to the CSS file, so `./src` resolved to
the non-existent `src/src/` directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pull/11749/head
afc163 5 months ago
parent
commit
91e7438d26
  1. 36
      postcss.config.js
  2. 2
      src/tailwind.css

36
postcss.config.js

@ -1,5 +1,35 @@
module.exports = { const path = require('path');
plugins: { const fs = require('fs');
'@tailwindcss/postcss': {},
/**
* Workaround for turbopack Windows path doubling bug.
* On Windows, turbopack may pass a doubled relative path as the `from` option
* to PostCSS (e.g. `./Desktop/demo/project/src/file.css` instead of `./src/file.css`),
* causing `path.resolve(cwd, from)` to produce a non-existent doubled path.
* This plugin detects and corrects the path before @tailwindcss/postcss reads it.
* @see https://github.com/ant-design/ant-design-pro/issues/11747
*/
const fixWindowsPathPlugin = {
postcssPlugin: 'fix-turbopack-windows-path',
Once(_root, { result }) {
const from = result.opts.from;
if (!from || fs.existsSync(from)) return;
const cwd = process.cwd();
const resolved = path.resolve(from);
const relative = path.relative(cwd, resolved);
const parts = relative.split(path.sep);
for (let i = 1; i < parts.length; i++) {
const candidate = path.join(cwd, ...parts.slice(i));
if (fs.existsSync(candidate)) {
result.opts.from = candidate;
return;
}
}
}, },
}; };
module.exports = {
plugins: [fixWindowsPathPlugin, require('@tailwindcss/postcss')],
};

2
src/tailwind.css

@ -1,3 +1,3 @@
@import "tailwindcss"; @import "tailwindcss";
@source "./src"; @source ".";

Loading…
Cancel
Save