Unverified Commit 41d1757b authored by Dmitry Rybin's avatar Dmitry Rybin Committed by GitHub

fix: 9919 Add warning when no config is exported from next.con… (#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: 's avatarJJ Kasper <jj@jjsweb.site>
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent 3cb7b443
# Detected next.config.js, no exported configuration found
#### Why This Warning Occurred
There is no object exported from next.config.js or the object is empty.
#### Possible Ways to Fix It
Check if you correctly export configuration in `next.config.js` file:
```
module.exports = {
/* config options here */
}
```
### Useful Links
- [Introduction to next.config.js](https://nextjs.org/docs/api-reference/next.config.js/introduction)
......@@ -229,6 +229,14 @@ export default function loadConfig(
phase,
userConfigModule.default || userConfigModule
)
if (Object.keys(userConfig).length === 0) {
console.warn(
chalk.yellow.bold('Warning: ') +
'Detected next.config.js, no exported configuration found. https://err.sh/zeit/next.js/empty-configuration'
)
}
if (userConfig.target && !targets.includes(userConfig.target)) {
throw new Error(
`Specified target is invalid. Provided: "${
......
/* eslint-disable */
{
experimental: {
basePath: '/docs'
}
}
export default () => <div>Hello World</div>
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import {
nextBuild,
launchApp,
findPort,
killApp,
waitFor,
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..')
describe('Empty configuration', () => {
it('should show relevant warning and compile successfully for next build', async () => {
const { stderr, stdout } = await nextBuild(appDir, [], {
stderr: true,
stdout: true,
})
expect(stdout).toMatch(/Compiled successfully./)
expect(stderr).toMatch(
/Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/
)
})
it('should show relevant warning and compile successfully for next dev', async () => {
let stderr = ''
const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
await waitFor(1000)
await killApp(app)
expect(stderr).toMatch(
/Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/
)
})
})
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