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 38a6d01 commit 733b781
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 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 @@ -50,6 +50,7 @@ export class Worker {
env: {
...((farmOptions.forkOptions?.env || {}) as any),
...process.env,
IS_NEXT_WORKER: 'true',
} as any,
},
maxRetries: 0,
Expand All @@ -75,7 +76,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}`
)

// if a child process doesn't exit gracefully, we want to bubble up the exit code to the parent process
Expand Down
12 changes: 6 additions & 6 deletions test/production/app-dir/build-output/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('production - app dir - build output', () => {

it('should log errors not caught by the worker without terminating the process', async () => {
expect(output).toContain('Error: Boom')
expect(output).not.toContain('Static worker exited with code: 78')
expect(output).not.toContain('Next.js build worker exited with code: 78')

const $ = await next.render$('/uncaught-error')
expect($('#sentinel').text()).toEqual('at buildtime')
Expand All @@ -66,7 +66,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')

expect(cliOutput).toContain('Static worker exited with code: 78')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})

it('should fail the build if you use a dynamic API outside of a render context - headers', async () => {
Expand All @@ -87,7 +87,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')

expect(cliOutput).toContain('Static worker exited with code: 78')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})

it('should fail the build if you use a dynamic API outside of a render context - searchParams', async () => {
Expand All @@ -106,7 +106,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')

expect(cliOutput).toContain('Static worker exited with code: 78')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})

it('should fail the build if you use a dynamic API outside of a render context - redirect', async () => {
Expand All @@ -127,7 +127,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')

expect(cliOutput).toContain('Static worker exited with code: 78')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})

it('should fail the build if you use a dynamic API outside of a render context - notFound', async () => {
Expand All @@ -148,6 +148,6 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')

expect(cliOutput).toContain('Static worker exited with code: 78')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 733b781

Please sign in to comment.