Skip to content

Commit

Permalink
fix: 9919 Add warning when no config is exported from next.con… (verc…
Browse files Browse the repository at this point in the history
…el#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>
  • Loading branch information
3 people authored and chibicode committed Feb 11, 2020
1 parent f5efc9e commit cd18d2b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
19 changes: 19 additions & 0 deletions errors/empty-configuration.md
@@ -0,0 +1,19 @@
# 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)
8 changes: 8 additions & 0 deletions packages/next/next-server/server/config.ts
Expand Up @@ -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: "${
Expand Down
6 changes: 6 additions & 0 deletions test/integration/config-empty/next.config.js
@@ -0,0 +1,6 @@
/* eslint-disable */
{
experimental: {
basePath: '/docs'
}
}
1 change: 1 addition & 0 deletions test/integration/config-empty/pages/index.js
@@ -0,0 +1 @@
export default () => <div>Hello World</div>
44 changes: 44 additions & 0 deletions test/integration/config-empty/test/index.test.js
@@ -0,0 +1,44 @@
/* 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/
)
})
})

0 comments on commit cd18d2b

Please sign in to comment.