diff --git a/errors/empty-configuration.md b/errors/empty-configuration.md new file mode 100644 index 0000000000000..316f928d6d1de --- /dev/null +++ b/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) diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 5fe42e75d3434..eee2087ff1f03 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -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: "${ diff --git a/test/integration/config-empty/next.config.js b/test/integration/config-empty/next.config.js new file mode 100644 index 0000000000000..0c04cc72881a0 --- /dev/null +++ b/test/integration/config-empty/next.config.js @@ -0,0 +1,6 @@ +/* eslint-disable */ +{ + experimental: { + basePath: '/docs' + } +} diff --git a/test/integration/config-empty/pages/index.js b/test/integration/config-empty/pages/index.js new file mode 100644 index 0000000000000..02d90896bf336 --- /dev/null +++ b/test/integration/config-empty/pages/index.js @@ -0,0 +1 @@ +export default () =>
Hello World
diff --git a/test/integration/config-empty/test/index.test.js b/test/integration/config-empty/test/index.test.js new file mode 100644 index 0000000000000..f0f3eb5ed11a0 --- /dev/null +++ b/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/ + ) + }) +})