Browse Source

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

Set globalThis.__tw_resolve in postcss.config.js to bypass
enhanced-resolve's CachedInputFileSystem, which caches stale
negative results on Windows (e.g. when Windows Defender scans
node_modules). Also fix @source path from "./src" to "."
since the directive is relative to the CSS file location.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
pull/11756/head
afc163 3 weeks ago
parent
commit
aebc8587f5
  1. 32
      postcss.config.js
  2. 2
      src/tailwind.css

32
postcss.config.js

@ -1,3 +1,35 @@
const path = require('path');
// Workaround for https://github.com/ant-design/ant-design-pro/issues/11747
// On Windows, @tailwindcss/node uses enhanced-resolve with a 4-second
// CachedInputFileSystem that can cache stale negative results (e.g. when
// Windows Defender locks node_modules). This causes intermittent
// "Can't resolve 'tailwindcss'" errors. Setting __tw_resolve bypasses
// enhanced-resolve by using Node.js require.resolve, which is reliable.
if (typeof globalThis.__tw_resolve !== 'function') {
globalThis.__tw_resolve = (specifier, fromDir) => {
if (specifier.startsWith('.') || specifier.startsWith('/')) return;
try {
const pkgJsonPath = require.resolve(specifier + '/package.json', {
paths: [fromDir],
});
const pkg = require(pkgJsonPath);
const pkgDir = path.dirname(pkgJsonPath);
if (pkg.exports?.['.']?.style) {
return path.join(pkgDir, pkg.exports['.'].style);
}
if (pkg.style) {
return path.join(pkgDir, pkg.style);
}
const indexPath = path.join(pkgDir, 'index.css');
try {
require('fs').accessSync(indexPath);
return indexPath;
} catch {}
} catch {}
};
}
module.exports = {
plugins: {
'@tailwindcss/postcss': {},

2
src/tailwind.css

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

Loading…
Cancel
Save