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

fix: 9919 Add warning when no config is exported from next.config.js #10228

Merged
merged 7 commits into from Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
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 @@ -228,6 +228,14 @@ export default function loadConfig(
phase,
userConfigModule.default || userConfigModule
)

if (Object.keys(userConfig).length === 0) {
console.warn(
chalk.yellow.bold('Warning: ') +
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
'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', () => {
ijjk marked this conversation as resolved.
Show resolved Hide resolved
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/
)
})
})