diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 055118cfcf396..85b50ff02002b 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -388,7 +388,11 @@ export default async function exportApp( }) ) - if (!exportPathMap['/404'] && !exportPathMap['/404.html']) { + if ( + !options.buildExport && + !exportPathMap['/404'] && + !exportPathMap['/404.html'] + ) { exportPathMap['/404'] = exportPathMap['/404.html'] = { page: '/_error', } diff --git a/test/integration/static-404/test/index.test.js b/test/integration/static-404/test/index.test.js index 308d910fc9adb..12852344d7e30 100644 --- a/test/integration/static-404/test/index.test.js +++ b/test/integration/static-404/test/index.test.js @@ -59,15 +59,18 @@ describe('Static 404 page', () => { ` import Error from 'next/error' export default class MyError extends Error { - static getInitialProps() { + static getInitialProps({ statusCode, req }) { + if (req.url === '/404' || req.url === '/404.html') { + throw new Error('exported 404 unexpectedly!!!') + } return { - statusCode: 404 + statusCode, } } } ` ) - await nextBuild(appDir) + await nextBuild(appDir, undefined, { stderr: true, stdout: true }) await fs.remove(errorPage) })