因postcss.config.js问题导致TailwindCSS与NextJS集成失败
Next.js集成TailwindCSS报错求助(postcss.config.js相关)
我已按官方指引完成从Vite到Next.js的项目迁移,但在集成TailwindCSS时,严格遵循官方文档操作后仍出现如下报错:

反复排查后确定问题根源在postcss.config.js文件,但毫无解决头绪。移除该文件后报错消失,但TailwindCSS也无法正常工作。本地运行dev server和Docker部署都试过,均未解决问题,也没找到相似案例,恳请协助解决。
相关代码文件
1. postcss.config.js
export default { plugins: { tailwindcss: {}, autoprefixer: {}, }, };
2. tsconfig.json
{ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "allowJs": true, "forceConsistentCasingInFileNames": true, "incremental": true, "paths": { "@/*": ["/*"] }, /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "esModuleInterop": true, "noEmit": true, "jsx": "preserve", /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "plugins": [{ "name": "next" }] }, "include": ["./dist/types/**/*.ts", "./next-env.d.ts"], "exclude": ["./node_modules/"] }
3. next.config.mjs
/** @type {import('next').NextConfig} */ const nextConfig = { output: "export", // Outputs a Single-Page Application (SPA) distDir: "./dist", // Changes the build output directory to `./dist/` }; export default nextConfig;
内容的提问来源于stack exchange,提问作者Hsun
相关产品推荐
相关产品推荐

