Skip to content

Commit d390c3d

Browse files
authored
Fix build traces case (#56817)
This ensures our `readFile` handling for tracing we previously had is maintained. Test deployment with the provided reproduction can be seen here: https://react-pdf-repro-jeqgyhmek-vtest314-ijjk-testing.vercel.app/ Fixes: #56676
1 parent 46d56c6 commit d390c3d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/next/src/build/collect-build-traces.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { defaultOverrides } from '../server/require-hook'
2424
import { nodeFileTrace } from 'next/dist/compiled/@vercel/nft'
2525
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
2626
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
27+
import isError from '../lib/is-error'
2728

2829
const debug = debugOriginal('next:build:build-traces')
2930

@@ -339,6 +340,45 @@ export async function collectBuildTraces({
339340
base: outputFileTracingRoot,
340341
processCwd: dir,
341342
mixedModules: true,
343+
async readFile(p) {
344+
try {
345+
return await fs.readFile(p, 'utf8')
346+
} catch (e) {
347+
if (isError(e) && (e.code === 'ENOENT' || e.code === 'EISDIR')) {
348+
// handle temporary internal webpack files
349+
if (p.match(/static[/\\]media/)) {
350+
return ''
351+
}
352+
return null
353+
}
354+
throw e
355+
}
356+
},
357+
async readlink(p) {
358+
try {
359+
return await fs.readlink(p)
360+
} catch (e) {
361+
if (
362+
isError(e) &&
363+
(e.code === 'EINVAL' ||
364+
e.code === 'ENOENT' ||
365+
e.code === 'UNKNOWN')
366+
) {
367+
return null
368+
}
369+
throw e
370+
}
371+
},
372+
async stat(p) {
373+
try {
374+
return await fs.stat(p)
375+
} catch (e) {
376+
if (isError(e) && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) {
377+
return null
378+
}
379+
throw e
380+
}
381+
},
342382
})
343383
const reasons = result.reasons
344384
const fileList = result.fileList

0 commit comments

Comments
 (0)