From ac4acf24f2198a46a14a19b2d31a2dddfb566225 Mon Sep 17 00:00:00 2001 From: Justin Braithwaite Date: Wed, 8 Sep 2021 12:13:41 -1000 Subject: [PATCH] Restore NEXT_PHASE `process.env.NEXT_PHASE` was moved in https://github.com/vercel/next.js/pull/20900 to be set during `staticCheckSpan.traceAsyncFn`. I believe this to be a mistake, the NEXT_PHASE should be set earlier in the code execution. On a personal note, this impacts an application I am developing where we rely on the environment variable `NEXT_PHASE` to be set but is `undefined` when we check it. --- packages/next/build/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 679f34323ce84df..d3027e12b7ab263 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -681,6 +681,9 @@ export default async function build( ? require.resolve('./worker') : require.resolve('./utils') let infoPrinted = false + + process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD + const staticWorkers = new Worker(staticWorker, { timeout: timeout * 1000, onRestart: (method, [arg], attempts) => { @@ -741,8 +744,6 @@ export default async function build( hasSsrAmpPages, hasNonStaticErrorPage, } = await staticCheckSpan.traceAsyncFn(async () => { - process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD - const runtimeEnvConfig = { publicRuntimeConfig: config.publicRuntimeConfig, serverRuntimeConfig: config.serverRuntimeConfig,