Skip to content

Commit 733b781

Browse files
committed
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
1 parent 38a6d01 commit 733b781

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

packages/next/src/lib/verify-typescript-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export async function verifyTypeScriptSetup({
164164
*/
165165

166166
// we are in a worker, print the error message and exit the process
167-
if (process.env.JEST_WORKER_ID) {
167+
if (process.env.IS_NEXT_WORKER) {
168168
if (err instanceof Error) {
169169
console.error(err.message)
170170
} else {

packages/next/src/lib/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class Worker {
5050
env: {
5151
...((farmOptions.forkOptions?.env || {}) as any),
5252
...process.env,
53+
IS_NEXT_WORKER: 'true',
5354
} as any,
5455
},
5556
maxRetries: 0,
@@ -75,7 +76,7 @@ export class Worker {
7576
worker._child?.on('exit', (code, signal) => {
7677
if ((code || (signal && signal !== 'SIGINT')) && this._worker) {
7778
logger.error(
78-
`Static worker exited with code: ${code} and signal: ${signal}`
79+
`Next.js build worker exited with code: ${code} and signal: ${signal}`
7980
)
8081

8182
// if a child process doesn't exit gracefully, we want to bubble up the exit code to the parent process

test/production/app-dir/build-output/index.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('production - app dir - build output', () => {
4242

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

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

69-
expect(cliOutput).toContain('Static worker exited with code: 78')
69+
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
7070
})
7171

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

90-
expect(cliOutput).toContain('Static worker exited with code: 78')
90+
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
9191
})
9292

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

109-
expect(cliOutput).toContain('Static worker exited with code: 78')
109+
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
110110
})
111111

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

130-
expect(cliOutput).toContain('Static worker exited with code: 78')
130+
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
131131
})
132132

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

151-
expect(cliOutput).toContain('Static worker exited with code: 78')
151+
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
152152
})
153153
})

test/production/app-dir/worker-restart/worker-restart.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('worker-restart', () => {
5656

5757
const output = stdout + stderr
5858
expect(output).toContain(
59-
'Static worker exited with code: null and signal: SIGKILL'
59+
'Next.js build worker exited with code: null and signal: SIGKILL'
6060
)
6161
})
6262
})

0 commit comments

Comments
 (0)