From aebc8587f54291137ad0502cb97917ca737fbb69 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 4 May 2026 23:28:42 +0800 Subject: [PATCH] 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 --- postcss.config.js | 32 ++++++++++++++++++++++++++++++++ src/tailwind.css | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/postcss.config.js b/postcss.config.js index e5640725..2363ecf4 100644 --- a/postcss.config.js +++ b/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': {}, diff --git a/src/tailwind.css b/src/tailwind.css index 79550f5d..a41506cf 100644 --- a/src/tailwind.css +++ b/src/tailwind.css @@ -1,3 +1,3 @@ @import "tailwindcss"; -@source "./src"; +@source ".";