Unverified Commit 8ee2d3f7 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

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
parent e9428bba
...@@ -164,7 +164,7 @@ export async function verifyTypeScriptSetup({ ...@@ -164,7 +164,7 @@ export async function verifyTypeScriptSetup({
*/ */
// we are in a worker, print the error message and exit the process // 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) { if (err instanceof Error) {
console.error(err.message) console.error(err.message)
} else { } else {
......
...@@ -50,6 +50,7 @@ export class Worker { ...@@ -50,6 +50,7 @@ export class Worker {
env: { env: {
...((farmOptions.forkOptions?.env || {}) as any), ...((farmOptions.forkOptions?.env || {}) as any),
...process.env, ...process.env,
IS_NEXT_WORKER: 'true',
} as any, } as any,
}, },
maxRetries: 0, maxRetries: 0,
...@@ -75,7 +76,7 @@ export class Worker { ...@@ -75,7 +76,7 @@ export class Worker {
worker._child?.on('exit', (code, signal) => { worker._child?.on('exit', (code, signal) => {
if ((code || (signal && signal !== 'SIGINT')) && this._worker) { if ((code || (signal && signal !== 'SIGINT')) && this._worker) {
logger.error( 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 // if a child process doesn't exit gracefully, we want to bubble up the exit code to the parent process
......
...@@ -42,7 +42,7 @@ describe('production - app dir - build output', () => { ...@@ -42,7 +42,7 @@ describe('production - app dir - build output', () => {
it('should log errors not caught by the worker without terminating the process', async () => { it('should log errors not caught by the worker without terminating the process', async () => {
expect(output).toContain('Error: Boom') 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') const $ = await next.render$('/uncaught-error')
expect($('#sentinel').text()).toEqual('at buildtime') expect($('#sentinel').text()).toEqual('at buildtime')
...@@ -66,7 +66,7 @@ describe('production - app dir - build output', () => { ...@@ -66,7 +66,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build() const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx') 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 () => { 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', () => { ...@@ -87,7 +87,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build() const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx') 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 () => { 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', () => { ...@@ -106,7 +106,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build() const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx') 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 () => { 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', () => { ...@@ -127,7 +127,7 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build() const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx') 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 () => { 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', () => { ...@@ -148,6 +148,6 @@ describe('production - app dir - build output', () => {
const { cliOutput } = await next.build() const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx') 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')
}) })
}) })
...@@ -56,7 +56,7 @@ describe('worker-restart', () => { ...@@ -56,7 +56,7 @@ describe('worker-restart', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
'Static worker exited with code: null and signal: SIGKILL' 'Next.js build worker exited with code: null and signal: SIGKILL'
) )
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment