Commit 5c3f9ba7 authored by Joe Haddad's avatar Joe Haddad Committed by JJ Kasper

Add Specific Error for Function in PostCSS Config (#9815)

parent 921f7544
...@@ -99,6 +99,12 @@ export async function getPostCssPlugins( ...@@ -99,6 +99,12 @@ export async function getPostCssPlugins(
config = { plugins: getDefaultPlugins() } config = { plugins: getDefaultPlugins() }
} }
if (typeof config === 'function') {
throw new Error(
`Your custom PostCSS configuration may not export a function. Please export a plain object instead.`
)
}
// Warn user about configuration keys which are not respected // Warn user about configuration keys which are not respected
const invalidKey = Object.keys(config).find(key => key !== 'plugins') const invalidKey = Object.keys(config).find(key => key !== 'plugins')
if (invalidKey) { if (invalidKey) {
......
...@@ -305,3 +305,20 @@ describe('Bad CSS Customization Array (7)', () => { ...@@ -305,3 +305,20 @@ describe('Bad CSS Customization Array (7)', () => {
expect(stderr).toMatch(/Build error occurred/) expect(stderr).toMatch(/Build error occurred/)
}) })
}) })
describe('Bad CSS Customization Function', () => {
const appDir = join(fixturesDir, 'bad-custom-configuration-func')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should fail the build', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch(
/Your custom PostCSS configuration may not export a function/
)
expect(stderr).toMatch(/Build error occurred/)
})
})
import React from 'react'
import App from 'next/app'
import '../styles/global.css'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp
module.exports = function() {
return { plugins: [] }
}
/* this should be transformed to width/height */
.video {
max-size: 400px 300px;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment