Skip to content

Commit

Permalink
Fix build traces case (vercel#56817)
Browse files Browse the repository at this point in the history
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: vercel#56676
  • Loading branch information
ijjk committed Oct 13, 2023
1 parent 46d56c6 commit d390c3d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { defaultOverrides } from '../server/require-hook'
import { nodeFileTrace } from 'next/dist/compiled/@vercel/nft'
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import isError from '../lib/is-error'

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

Expand Down Expand Up @@ -339,6 +340,45 @@ export async function collectBuildTraces({
base: outputFileTracingRoot,
processCwd: dir,
mixedModules: true,
async readFile(p) {
try {
return await fs.readFile(p, 'utf8')
} catch (e) {
if (isError(e) && (e.code === 'ENOENT' || e.code === 'EISDIR')) {
// handle temporary internal webpack files
if (p.match(/static[/\\]media/)) {
return ''
}
return null
}
throw e
}
},
async readlink(p) {
try {
return await fs.readlink(p)
} catch (e) {
if (
isError(e) &&
(e.code === 'EINVAL' ||
e.code === 'ENOENT' ||
e.code === 'UNKNOWN')
) {
return null
}
throw e
}
},
async stat(p) {
try {
return await fs.stat(p)
} catch (e) {
if (isError(e) && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) {
return null
}
throw e
}
},
})
const reasons = result.reasons
const fileList = result.fileList
Expand Down

0 comments on commit d390c3d

Please sign in to comment.