Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific warning for require() PostCSS plugin #10121

Merged
merged 1 commit into from Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/next/build/webpack/config/blocks/css/plugins.ts
Expand Up @@ -193,6 +193,15 @@ export async function getPostCssPlugins(
}
throw new Error(genericErrorText)
}
} else if (typeof plugin === 'function') {
console.error(
`${chalk.red.bold(
'Error'
)}: A PostCSS Plugin was passed as a function using require(), but it must be provided as a ${chalk.bold(
'string'
)}.`
)
throw new Error(genericErrorText)
} else {
console.error(
`${chalk.red.bold(
Expand Down
17 changes: 17 additions & 0 deletions test/integration/css-customization/test/index.test.js
Expand Up @@ -331,6 +331,23 @@ describe('Bad CSS Customization Array (7)', () => {
})
})

describe('Bad CSS Customization Array (8)', () => {
const appDir = join(fixturesDir, 'bad-custom-configuration-arr-8')

beforeAll(async () => {
await remove(join(appDir, '.next'))
})

it('should fail the build', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })

expect(stderr).toMatch(
/A PostCSS Plugin was passed as a function using require\(\), but it must be provided as a string/
)
expect(stderr).toMatch(/Build error occurred/)
})
})

describe('Bad CSS Customization Function', () => {
const appDir = join(fixturesDir, 'bad-custom-configuration-func')

Expand Down
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,3 @@
export default function Home() {
return <div />
}
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require('postcss-trolling')],
}
@@ -0,0 +1,14 @@
/* this should pass through untransformed */
@media (480px <= width < 768px) {
a::before {
content: '';
}
::placeholder {
color: green;
}
}

/* this should be transformed to width/height */
.video {
-xyz-max-size: 400rem 300rem;
}