From db91fbf407b45f075cc4c5b18f3b46c893c42aa0 Mon Sep 17 00:00:00 2001 From: Justin Braithwaite Date: Wed, 15 Dec 2021 22:17:42 -0800 Subject: [PATCH] Prevent NEXT_PHASE env change in workers (#28941) `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. Co-authored-by: JJ Kasper --- packages/next/build/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index b42dddbab11fb05..600e12062d43366 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -783,6 +783,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) => { @@ -834,7 +837,6 @@ export default async function build( > const analysisBegin = process.hrtime() - const staticCheckSpan = nextBuildSpan.traceChild('static-check') const { customAppGetInitialProps, @@ -843,8 +845,6 @@ export default async function build( hasSsrAmpPages, hasNonStaticErrorPage, } = await staticCheckSpan.traceAsyncFn(async () => { - process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD - const { configFileName, publicRuntimeConfig, serverRuntimeConfig } = config const runtimeEnvConfig = { publicRuntimeConfig, serverRuntimeConfig }