Skip to content

Commit

Permalink
fix: ensure lint worker errors aren't silenced (#75766)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ztanner committed Feb 7, 2025
1 parent f27ce02 commit a614aa5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/lib/verify-typescript-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/lib/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Worker {
env: {
...((farmOptions.forkOptions?.env || {}) as any),
...process.env,
IS_NEXT_WORKER: 'true',
} as any,
},
}) as JestWorker
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
})

0 comments on commit a614aa5

Please sign in to comment.