diff --git a/errors/postcss-function.md b/errors/postcss-function.md new file mode 100644 index 000000000000000..83b301eb9d0821f --- /dev/null +++ b/errors/postcss-function.md @@ -0,0 +1,30 @@ +# PostCSS Configuration Is a Function + +#### Why This Error Occurred + +The project's custom PostCSS configuration exports a function instead of an object. + +#### Possible Ways to Fix It + +Adjust the custom PostCSS configuration to not export a function. +Instead, return a plain object—if you need environment information, read it from `process.env`. + +**Before** + +```js +module.exports = ({ env }) => ({ + plugins: { + 'postcss-plugin': env === 'production' ? {} : false, + }, +}) +``` + +**After** + +```js +module.exports = { + plugins: { + 'postcss-plugin': process.env.NODE_ENV === 'production' ? {} : false, + }, +} +``` diff --git a/packages/next/build/webpack/config/blocks/css/plugins.ts b/packages/next/build/webpack/config/blocks/css/plugins.ts index caa338d60a78172..30a8e39be03997d 100644 --- a/packages/next/build/webpack/config/blocks/css/plugins.ts +++ b/packages/next/build/webpack/config/blocks/css/plugins.ts @@ -119,7 +119,8 @@ export async function getPostCssPlugins( if (typeof config === 'function') { throw new Error( - `Your custom PostCSS configuration may not export a function. Please export a plain object instead.` + `Your custom PostCSS configuration may not export a function. Please export a plain object instead.\n` + + 'Read more: https://err.sh/next.js/postcss-function' ) }