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 warning when built-in CSS/SCSS support is disabled #10942

Merged
merged 1 commit into from Mar 10, 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
18 changes: 18 additions & 0 deletions errors/built-in-css-disabled.md
@@ -0,0 +1,18 @@
# Built-in CSS Support Disabled

#### Why This Error Occurred

Custom CSS configuration was added in `next.config.js` which disables the built-in CSS/SCSS support to prevent conflicting configuration.

A legacy plugin such as `@zeit/next-css` being added in `next.config.js` can cause this message.

#### Possible Ways to Fix It

If you would like to leverage the built-in CSS/SCSS support you can remove any custom CSS configuration or any plugins like `@zeit/next-css` or `@zeit/next-sass` in your `next.config.js`.

If you would prefer not to leverage the built-in support you can ignore this message.

### Useful Links

- [Built-in CSS Support docs](https://nextjs.org/docs/basic-features/built-in-css-support)
- [Custom webpack config docs](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config)
12 changes: 12 additions & 0 deletions packages/next/build/webpack-config.ts
@@ -1,3 +1,4 @@
import chalk from 'chalk'
import crypto from 'crypto'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import path from 'path'
Expand Down Expand Up @@ -963,6 +964,17 @@ export default async function getBaseWebpackConfig(
) ?? false

if (hasUserCssConfig) {
// only show warning for one build
if (isServer) {
console.warn(
chalk.yellow.bold('Warning: ') +
chalk.bold(
'Built-in CSS support is being disabled due to custom CSS configuration being detected.\n'
) +
'See here for more info: https://err.sh/next.js/built-in-css-disabled\n'
)
}

if (webpackConfig.module?.rules.length) {
// Remove default CSS Loader
webpackConfig.module.rules = webpackConfig.module.rules.filter(
Expand Down
6 changes: 5 additions & 1 deletion test/integration/css-customization/test/index.test.js
Expand Up @@ -83,11 +83,15 @@ describe('Legacy Next-CSS Customization', () => {
})

it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
const { code, stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
expect(stderr).toMatch(
/Built-in CSS support is being disabled due to custom CSS configuration being detected/
)
})

it(`should've compiled and prefixed`, async () => {
Expand Down