diff --git a/packages/next/client/components/hooks-server.ts b/packages/next/client/components/hooks-server.ts index e0465fd1bd3e8..7a47daa19e54c 100644 --- a/packages/next/client/components/hooks-server.ts +++ b/packages/next/client/components/hooks-server.ts @@ -26,7 +26,7 @@ if (process.env.NEXT_RUNTIME !== 'edge' && typeof window === 'undefined') { function useStaticGenerationBailout(reason: string) { const staticGenerationStore = - 'getStore' in staticGenerationAsyncStorage + staticGenerationAsyncStorage && 'getStore' in staticGenerationAsyncStorage ? staticGenerationAsyncStorage?.getStore() : staticGenerationAsyncStorage diff --git a/packages/next/export/worker.ts b/packages/next/export/worker.ts index ebd32f9b866fb..f7d1cb230cea2 100644 --- a/packages/next/export/worker.ts +++ b/packages/next/export/worker.ts @@ -28,6 +28,7 @@ import RenderResult from '../server/render-result' import isError from '../lib/is-error' import { addRequestMeta } from '../server/request-meta' import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' +import { REDIRECT_ERROR_CODE } from '../client/components/redirect' loadRequireHook() const envConfig = require('../shared/lib/runtime-config') @@ -419,7 +420,10 @@ export default async function exportPage({ ) } } catch (err) { - if (!(err instanceof DynamicServerError)) { + if ( + !(err instanceof DynamicServerError) && + (err as any).code !== REDIRECT_ERROR_CODE + ) { throw err } }