diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 57a50d0df8b0..e3ead7592fe2 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -228,6 +228,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.' + ) + } + if (userConfig.target && !targets.includes(userConfig.target)) { throw new Error( `Specified target is invalid. Provided: "${ diff --git a/test/isolated/_resolvedata/no-export/next.config.js b/test/isolated/_resolvedata/no-export/next.config.js new file mode 100644 index 000000000000..ecd8a39e2a09 --- /dev/null +++ b/test/isolated/_resolvedata/no-export/next.config.js @@ -0,0 +1,3 @@ +// eslint-disable-next-line no-lone-blocks +{ +} diff --git a/test/isolated/config.test.js b/test/isolated/config.test.js index 060799290715..e88cefa21050 100644 --- a/test/isolated/config.test.js +++ b/test/isolated/config.test.js @@ -108,4 +108,19 @@ describe('config', () => { ) expect(config.__test__ext).toBe('js') }) + + it('Should log a warning when no exported configuration found', () => { + const spy = jest.spyOn(console, 'warn') + + loadConfig( + PHASE_DEVELOPMENT_SERVER, + join(__dirname, '_resolvedata', 'no-export') + ) + + expect(spy.mock.calls[0][0]).toMatch( + 'Detected next.config.js, no exported configuration found' + ) + + spy.mockRestore() + }) })