AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Fails To Evaluate Variable-Assigned Default Exports In Postcss.Config.Mjs

Next.js development server with Turbopack throws 'PostCSS config is undefined' when postcss.config.mjs uses a variable for the default export, even though the module is valid ESM. Direct object literal export works as a workaround.

highConfidence 92%Next.jsAffected V16.3.0

Origin Analysis

Turbopack's PostCSS configuration loader only recognizes inline ObjectExpression or FunctionExpression in the ExportDefaultDeclaration. When the default export is an Identifier referencing a previously declared variable, the evaluator fails to resolve the binding and returns undefined.
1. Create a Next.js 16.3.0 project with postcss.config.mjs containing: ```javascript const config = { plugins: { "@tailwindcss/postcss": {}, }, }; export default config; ``` 2. Run `next dev`. 3. Observe terminal error: `Error: PostCSS config is undefined (make sure to export an function or object from config file)` when loading `globals.css`.

Fixing Code Block

Edge Case Audit

This is a temporary workaround and does not fix the underlying Turbopack bug. It may reduce readability or reusability of the config object. After upgrading to a Next.js version that resolves the issue, consider reverting to the variable-based approach to maintain code clarity. No concurrency or multi-threading risks are introduced by this change; the only risk is potential merge conflicts if the file is later refactored to use variables again. Rollback: simply restore the previous `const config = {...}; export default config;` syntax.

Ecosystem Topology