From c612fb126138c6cd77c8bef4b0454aba3d8eff2d Mon Sep 17 00:00:00 2001 From: Dmitry Rybin Date: Thu, 23 Jan 2020 09:43:43 +0100 Subject: [PATCH 1/6] fix: 9919 no exported config found --- packages/next/next-server/server/config.ts | 8 ++++++++ .../_resolvedata/no-export/next.config.js | 3 +++ test/isolated/config.test.js | 15 +++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/isolated/_resolvedata/no-export/next.config.js diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 57a50d0df8b0b21..e3ead7592fe291e 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 000000000000000..ecd8a39e2a097ac --- /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 0607992907152ba..e88cefa2105093b 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() + }) }) From f6cdb7b09e129c43c537c10e40a5d32abdd790f3 Mon Sep 17 00:00:00 2001 From: Dmitry Rybin Date: Thu, 23 Jan 2020 19:56:23 +0100 Subject: [PATCH 2/6] fix: 9919 remove isolated test, add integration --- test/integration/config-empty/next.config.js | 6 ++++++ test/integration/config-empty/pages/index.js | 1 + .../integration/config-empty/test/index.test.js | 17 +++++++++++++++++ .../_resolvedata/no-export/next.config.js | 3 --- test/isolated/config.test.js | 15 --------------- 5 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 test/integration/config-empty/next.config.js create mode 100644 test/integration/config-empty/pages/index.js create mode 100644 test/integration/config-empty/test/index.test.js delete mode 100644 test/isolated/_resolvedata/no-export/next.config.js diff --git a/test/integration/config-empty/next.config.js b/test/integration/config-empty/next.config.js new file mode 100644 index 000000000000000..0c04cc72881a0fa --- /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 000000000000000..02d90896bf336a9 --- /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 000000000000000..4e850c44b9f24c6 --- /dev/null +++ b/test/integration/config-empty/test/index.test.js @@ -0,0 +1,17 @@ +/* eslint-env jest */ +/* global jasmine */ +import { join } from 'path' +import { nextBuild } from 'next-test-utils' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 + +describe('Empty configuration', () => { + it('should show relevant warning when configuration is not found', async () => { + const { stdout } = await nextBuild(join(__dirname, '..'), [], { + stdout: true, + }) + expect(stdout).not.toMatch( + /Warning: Detected next.config.js, no exported configuration found./ + ) + }) +}) diff --git a/test/isolated/_resolvedata/no-export/next.config.js b/test/isolated/_resolvedata/no-export/next.config.js deleted file mode 100644 index ecd8a39e2a097ac..000000000000000 --- a/test/isolated/_resolvedata/no-export/next.config.js +++ /dev/null @@ -1,3 +0,0 @@ -// eslint-disable-next-line no-lone-blocks -{ -} diff --git a/test/isolated/config.test.js b/test/isolated/config.test.js index e88cefa2105093b..0607992907152ba 100644 --- a/test/isolated/config.test.js +++ b/test/isolated/config.test.js @@ -108,19 +108,4 @@ 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() - }) }) From 5595d6457f5bf45029f0c4c0b2e8386c6ae60499 Mon Sep 17 00:00:00 2001 From: Dmitry Rybin Date: Sat, 25 Jan 2020 11:45:29 +0100 Subject: [PATCH 3/6] fix: 9919 add check for successfull compilation and fix warnin check --- test/integration/config-empty/test/index.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/integration/config-empty/test/index.test.js b/test/integration/config-empty/test/index.test.js index 4e850c44b9f24c6..fddde8dc8bb3bb5 100644 --- a/test/integration/config-empty/test/index.test.js +++ b/test/integration/config-empty/test/index.test.js @@ -6,12 +6,15 @@ import { nextBuild } from 'next-test-utils' jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 describe('Empty configuration', () => { - it('should show relevant warning when configuration is not found', async () => { - const { stdout } = await nextBuild(join(__dirname, '..'), [], { + it('should show relevant warning and compile successfully', async () => { + const { stderr, stdout } = await nextBuild(join(__dirname, '..'), [], { + stderr: true, stdout: true, }) - expect(stdout).not.toMatch( + + expect(stderr).toMatch( /Warning: Detected next.config.js, no exported configuration found./ ) + expect(stdout).toMatch(/Compiled successfully./) }) }) From 8327723b32b5d5ba27e77b90865741a6e3b5b1d9 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 26 Jan 2020 14:51:39 -0600 Subject: [PATCH 4/6] Add test for development output --- .../config-empty/test/index.test.js | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/integration/config-empty/test/index.test.js b/test/integration/config-empty/test/index.test.js index fddde8dc8bb3bb5..a480a0d6ac64ac0 100644 --- a/test/integration/config-empty/test/index.test.js +++ b/test/integration/config-empty/test/index.test.js @@ -1,20 +1,44 @@ /* eslint-env jest */ /* global jasmine */ import { join } from 'path' -import { nextBuild } from 'next-test-utils' +import { + nextBuild, + launchApp, + findPort, + killApp, + waitFor, +} from 'next-test-utils' -jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 + +const appDir = join(__dirname, '..') describe('Empty configuration', () => { - it('should show relevant warning and compile successfully', async () => { - const { stderr, stdout } = await nextBuild(join(__dirname, '..'), [], { + 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./ + ) + }) + + 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./ ) - expect(stdout).toMatch(/Compiled successfully./) }) }) From 568286d34b6c572b1cefbec798e1e0951c0f7a51 Mon Sep 17 00:00:00 2001 From: Dmitry Rybin Date: Tue, 28 Jan 2020 19:29:31 +0100 Subject: [PATCH 5/6] fix: 9919 add error page and link to it in warning --- errors/empty-configuration.md | 19 +++++++++++++++++++ packages/next/next-server/server/config.ts | 2 +- .../config-empty/test/index.test.js | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 errors/empty-configuration.md diff --git a/errors/empty-configuration.md b/errors/empty-configuration.md new file mode 100644 index 000000000000000..4ae858c806eda8e --- /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 export correctly 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 e3ead7592fe291e..955fc04999bcd48 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -232,7 +232,7 @@ export default function loadConfig( if (Object.keys(userConfig).length === 0) { console.warn( chalk.yellow.bold('Warning: ') + - 'Detected next.config.js, no exported configuration found.' + 'Detected next.config.js, no exported configuration found. https://err.sh/zeit/next.js/empty-configuration' ) } diff --git a/test/integration/config-empty/test/index.test.js b/test/integration/config-empty/test/index.test.js index a480a0d6ac64ac0..f0f3eb5ed11a050 100644 --- a/test/integration/config-empty/test/index.test.js +++ b/test/integration/config-empty/test/index.test.js @@ -21,7 +21,7 @@ describe('Empty configuration', () => { }) expect(stdout).toMatch(/Compiled successfully./) expect(stderr).toMatch( - /Warning: Detected next.config.js, no exported configuration found./ + /Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/ ) }) @@ -38,7 +38,7 @@ describe('Empty configuration', () => { await killApp(app) expect(stderr).toMatch( - /Warning: Detected next.config.js, no exported configuration found./ + /Warning: Detected next.config.js, no exported configuration found. https:\/\/err.sh\/zeit\/next.js\/empty-configuration/ ) }) }) From 356659b4e95153092c5d4fdd9485b5e2ae1b0852 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 28 Jan 2020 22:30:17 +0100 Subject: [PATCH 6/6] Update empty-configuration.md --- errors/empty-configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/empty-configuration.md b/errors/empty-configuration.md index 4ae858c806eda8e..316f928d6d1de35 100644 --- a/errors/empty-configuration.md +++ b/errors/empty-configuration.md @@ -6,7 +6,7 @@ There is no object exported from next.config.js or the object is empty. #### Possible Ways to Fix It -Check if you export correctly configuration in next.config.js file: +Check if you correctly export configuration in `next.config.js` file: ``` module.exports = {