Skip to content

Commit fde1ce2

Browse files
authored
Add warning when built-in CSS/SCSS support is disabled (vercel#10942)
1 parent a4ab088 commit fde1ce2

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

errors/built-in-css-disabled.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Built-in CSS Support Disabled
2+
3+
#### Why This Error Occurred
4+
5+
Custom CSS configuration was added in `next.config.js` which disables the built-in CSS/SCSS support to prevent conflicting configuration.
6+
7+
A legacy plugin such as `@zeit/next-css` being added in `next.config.js` can cause this message.
8+
9+
#### Possible Ways to Fix It
10+
11+
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`.
12+
13+
If you would prefer not to leverage the built-in support you can ignore this message.
14+
15+
### Useful Links
16+
17+
- [Built-in CSS Support docs](https://nextjs.org/docs/basic-features/built-in-css-support)
18+
- [Custom webpack config docs](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config)

packages/next/build/webpack-config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from 'chalk'
12
import crypto from 'crypto'
23
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
34
import path from 'path'
@@ -963,6 +964,17 @@ export default async function getBaseWebpackConfig(
963964
) ?? false
964965

965966
if (hasUserCssConfig) {
967+
// only show warning for one build
968+
if (isServer) {
969+
console.warn(
970+
chalk.yellow.bold('Warning: ') +
971+
chalk.bold(
972+
'Built-in CSS support is being disabled due to custom CSS configuration being detected.\n'
973+
) +
974+
'See here for more info: https://err.sh/next.js/built-in-css-disabled\n'
975+
)
976+
}
977+
966978
if (webpackConfig.module?.rules.length) {
967979
// Remove default CSS Loader
968980
webpackConfig.module.rules = webpackConfig.module.rules.filter(

test/integration/css-customization/test/index.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ describe('Legacy Next-CSS Customization', () => {
8383
})
8484

8585
it('should compile successfully', async () => {
86-
const { code, stdout } = await nextBuild(appDir, [], {
86+
const { code, stdout, stderr } = await nextBuild(appDir, [], {
8787
stdout: true,
88+
stderr: true,
8889
})
8990
expect(code).toBe(0)
9091
expect(stdout).toMatch(/Compiled successfully/)
92+
expect(stderr).toMatch(
93+
/Built-in CSS support is being disabled due to custom CSS configuration being detected/
94+
)
9195
})
9296

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

0 commit comments

Comments
 (0)