diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 878e5734f84c8..8c15bda295417 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1321,7 +1321,8 @@ export default class Server { if ( process.env.NODE_ENV !== 'production' && !using404Page && - (await this.hasPage('/_error')) + (await this.hasPage('/_error')) && + !(await this.hasPage('/404')) ) { this.customErrorNo404Warn() } diff --git a/test/integration/custom-error/test/index.test.js b/test/integration/custom-error/test/index.test.js index b58df310cb4d9..c42259d0c148d 100644 --- a/test/integration/custom-error/test/index.test.js +++ b/test/integration/custom-error/test/index.test.js @@ -13,6 +13,7 @@ import { jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 const appDir = join(__dirname, '..') +const page404 = join(appDir, 'pages/404.js') const nextConfig = join(appDir, 'next.config.js') let appPort let app @@ -27,6 +28,29 @@ const runTests = () => { const customErrNo404Match = /You have added a custom \/_error page without a custom \/404 page/ describe('Custom _error', () => { + describe('dev mode', () => { + let stderr = '' + + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort, { + onStderr(msg) { + stderr += msg || '' + }, + }) + }) + afterAll(() => killApp()) + + it('should not warn with /_error and /404 when rendering error first', async () => { + stderr = '' + await fs.writeFile(page404, 'export default