Skip to content

Commit

Permalink
Prevent NEXT_PHASE env change in workers (#28941)
Browse files Browse the repository at this point in the history
`process.env.NEXT_PHASE` was moved in #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 <jj@jjsweb.site>
  • Loading branch information
jbraithwaite and ijjk committed Dec 16, 2021
1 parent 12597f2 commit db91fbf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/next/build/index.ts
Expand Up @@ -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) => {
Expand Down Expand Up @@ -834,7 +837,6 @@ export default async function build(
>

const analysisBegin = process.hrtime()

const staticCheckSpan = nextBuildSpan.traceChild('static-check')
const {
customAppGetInitialProps,
Expand All @@ -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 }
Expand Down

0 comments on commit db91fbf

Please sign in to comment.