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 () =>