From a614aa5d5d6197ee49b5a741a078df2001a4c4e4 Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:59:26 -0800 Subject: [PATCH 1/2] fix: ensure lint worker errors aren't silenced (#75766) Errors thrown by the lint worker would only surface the error if `JEST_WORKER_ID` is present. This check was not reliably truthy in all cases (eg, when run with the vercel CLI, `JEST_WORKER_ID` wasn't present) which meant the build would fail with no helpful error message. Outside of that, it was a brittle check because if jest-worker ever changed or removed this env, or we replaced the underlying worker library, this would start failing. This updates the check to be a more explicit env variable that we control. Fixes NEXT-3994 --- packages/next/src/lib/verify-typescript-setup.ts | 2 +- packages/next/src/lib/worker.ts | 3 ++- test/production/app-dir/worker-restart/worker-restart.test.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/next/src/lib/verify-typescript-setup.ts b/packages/next/src/lib/verify-typescript-setup.ts index 5db275bc9cfb0..199bc1848fcc9 100644 --- a/packages/next/src/lib/verify-typescript-setup.ts +++ b/packages/next/src/lib/verify-typescript-setup.ts @@ -164,7 +164,7 @@ export async function verifyTypeScriptSetup({ */ // we are in a worker, print the error message and exit the process - if (process.env.JEST_WORKER_ID) { + if (process.env.IS_NEXT_WORKER) { if (err instanceof Error) { console.error(err.message) } else { diff --git a/packages/next/src/lib/worker.ts b/packages/next/src/lib/worker.ts index a23961ea63c04..9555caaa49c7d 100644 --- a/packages/next/src/lib/worker.ts +++ b/packages/next/src/lib/worker.ts @@ -48,6 +48,7 @@ export class Worker { env: { ...((farmOptions.forkOptions?.env || {}) as any), ...process.env, + IS_NEXT_WORKER: 'true', } as any, }, }) as JestWorker @@ -73,7 +74,7 @@ export class Worker { worker._child?.on('exit', (code, signal) => { if ((code || (signal && signal !== 'SIGINT')) && this._worker) { logger.error( - `Static worker exited with code: ${code} and signal: ${signal}` + `Next.js build worker exited with code: ${code} and signal: ${signal}` ) // We're restarting the worker, so we don't want to exit the parent process diff --git a/test/production/app-dir/worker-restart/worker-restart.test.ts b/test/production/app-dir/worker-restart/worker-restart.test.ts index ccf57b4a89eaa..95679d38e18aa 100644 --- a/test/production/app-dir/worker-restart/worker-restart.test.ts +++ b/test/production/app-dir/worker-restart/worker-restart.test.ts @@ -41,7 +41,7 @@ describe('worker-restart', () => { const output = stdout + stderr expect(output).toContain( - 'Static worker exited with code: null and signal: SIGKILL' + 'Next.js build worker exited with code: null and signal: SIGKILL' ) }) }) From 55974cfc3d6802ec129d2274a46db427a8a8700d Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Mon, 10 Feb 2025 10:37:04 -0800 Subject: [PATCH 2/2] test fix --- packages/next/src/lib/worker.ts | 2 +- test/production/app-dir/worker-restart/worker-restart.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/next/src/lib/worker.ts b/packages/next/src/lib/worker.ts index 9555caaa49c7d..fb5d9139480ff 100644 --- a/packages/next/src/lib/worker.ts +++ b/packages/next/src/lib/worker.ts @@ -97,7 +97,7 @@ export class Worker { if (!worker) return const resolve = resolveRestartPromise logger.warn( - `Sending SIGTERM signal to static worker due to timeout${ + `Sending SIGTERM signal to Next.js build worker due to timeout${ timeout ? ` of ${timeout / 1000} seconds` : '' }. Subsequent errors may be a result of the worker exiting.` ) diff --git a/test/production/app-dir/worker-restart/worker-restart.test.ts b/test/production/app-dir/worker-restart/worker-restart.test.ts index 95679d38e18aa..ad08460ecf1a3 100644 --- a/test/production/app-dir/worker-restart/worker-restart.test.ts +++ b/test/production/app-dir/worker-restart/worker-restart.test.ts @@ -13,10 +13,10 @@ describe('worker-restart', () => { const output = stdout + stderr expect(output).toContain( - 'Sending SIGTERM signal to static worker due to timeout of 10 seconds. Subsequent errors may be a result of the worker exiting.' + 'Sending SIGTERM signal to Next.js build worker due to timeout of 10 seconds. Subsequent errors may be a result of the worker exiting.' ) expect(output).toContain( - 'Static worker exited with code: null and signal: SIGTERM' + 'Next.js build worker exited with code: null and signal: SIGTERM' ) expect(output).toContain( 'Restarted static page generation for /bad-page because it took more than 10 seconds'