From cdfa826c865965cea988984bd50c3e81d80bb50f Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 18 Feb 2022 09:13:14 -0800 Subject: [PATCH 1/2] use env var for `isBuild` --- packages/nextjs/src/index.server.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts index b5852a392dba..1a8752e844ee 100644 --- a/packages/nextjs/src/index.server.ts +++ b/packages/nextjs/src/index.server.ts @@ -23,12 +23,20 @@ const domain = domainModule as typeof domainModule & { active: (domainModule.Dom // During build, the main process is invoked by // `node next build` // and child processes are invoked as -// `node /node_modules/jest-worker/build/workers/processChild.js`, -// whereas at runtime the process is invoked as +// `node /node_modules/.../jest-worker/processChild.js`. +// The former is (obviously) easy to recognize, but the latter could happen at runtime as well. Fortunately, the main +// process hits this file before any of the child processes do, so we're able to set an env variable which the child +// processes can then check. During runtime, the main process is invoked as // `node next start` // or -// `node /var/runtime/index.js`. -const isBuild = new RegExp('build').test(process.argv.toString()); +// `node /var/runtime/index.js`, +// so we never drop into the `if` in the first place. +let isBuild; +if (process.argv.includes('build') || process.env.BUILD_PHASE) { + process.env.BUILD_PHASE = 'true'; + isBuild = true; +} + const isVercel = !!process.env.VERCEL; /** Inits the Sentry NextJS SDK on node. */ From 83a765404e8ee565d2f497f9f9d746fc2f9a86a5 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 18 Feb 2022 10:26:58 -0800 Subject: [PATCH 2/2] initialize `isBuild` to false and namespace build flag --- packages/nextjs/src/index.server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts index 1a8752e844ee..2d3ff2b39abe 100644 --- a/packages/nextjs/src/index.server.ts +++ b/packages/nextjs/src/index.server.ts @@ -31,9 +31,9 @@ const domain = domainModule as typeof domainModule & { active: (domainModule.Dom // or // `node /var/runtime/index.js`, // so we never drop into the `if` in the first place. -let isBuild; -if (process.argv.includes('build') || process.env.BUILD_PHASE) { - process.env.BUILD_PHASE = 'true'; +let isBuild = false; +if (process.argv.includes('build') || process.env.SENTRY_BUILD_PHASE) { + process.env.SENTRY_BUILD_PHASE = 'true'; isBuild = true; }