Skip to content

Commit 41d1757

Browse files
dmitrikaijjktimneutkens
authored
fix: 9919 Add warning when no config is exported from next.con… (vercel#10228)
* fix: 9919 no exported config found * fix: 9919 remove isolated test, add integration * fix: 9919 add check for successfull compilation and fix warnin check * Add test for development output * fix: 9919 add error page and link to it in warning * Update empty-configuration.md Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
1 parent 3cb7b44 commit 41d1757

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

errors/empty-configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Detected next.config.js, no exported configuration found
2+
3+
#### Why This Warning Occurred
4+
5+
There is no object exported from next.config.js or the object is empty.
6+
7+
#### Possible Ways to Fix It
8+
9+
Check if you correctly export configuration in `next.config.js` file:
10+
11+
```
12+
module.exports = {
13+
/* config options here */
14+
}
15+
```
16+
17+
### Useful Links
18+
19+
- [Introduction to next.config.js](https://nextjs.org/docs/api-reference/next.config.js/introduction)

packages/next/next-server/server/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ export default function loadConfig(
229229
phase,
230230
userConfigModule.default || userConfigModule
231231
)
232+
233+
if (Object.keys(userConfig).length === 0) {
234+
console.warn(
235+
chalk.yellow.bold('Warning: ') +
236+
'Detected next.config.js, no exported configuration found. https://err.sh/zeit/next.js/empty-configuration'
237+
)
238+
}
239+
232240
if (userConfig.target && !targets.includes(userConfig.target)) {
233241
throw new Error(
234242
`Specified target is invalid. Provided: "${
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable */
2+
{
3+
experimental: {
4+
basePath: '/docs'
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => <div>Hello World</div>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-env jest */
2+
/* global jasmine */
3+
import { join } from 'path'
4+
import {
5+
nextBuild,
6+
launchApp,
7+
findPort,
8+
killApp,
9+
waitFor,
10+
} from 'next-test-utils'
11+
12+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
13+
14+
const appDir = join(__dirname, '..')
15+
16+
describe('Empty configuration', () => {
17+
it('should show relevant warning and compile successfully for next build', async () => {
18+
const { stderr, stdout } = await nextBuild(appDir, [], {
19+
stderr: true,
20+
stdout: true,
21+
})
22+
expect(stdout).toMatch(/Compiled successfully./)
23+
expect(stderr).toMatch(
24+
/Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/
25+
)
26+
})
27+
28+
it('should show relevant warning and compile successfully for next dev', async () => {
29+
let stderr = ''
30+
31+
const appPort = await findPort()
32+
const app = await launchApp(appDir, appPort, {
33+
onStderr(msg) {
34+
stderr += msg || ''
35+
},
36+
})
37+
await waitFor(1000)
38+
await killApp(app)
39+
40+
expect(stderr).toMatch(
41+
/Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/
42+
)
43+
})
44+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy