Commit 1589416e authored by Luke Sandberg's avatar Luke Sandberg Committed by Jiachi Liu

[turbopack] change server source maps in production to use relative paths (#85576)

Co-authored-by: 's avatarSebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>
parent 02bd4b5c
......@@ -1063,8 +1063,7 @@ pub async fn get_server_chunking_context_with_client_assets(
builder = builder.source_map_source_type(if next_mode.is_development() {
SourceMapSourceType::AbsoluteFileUri
} else {
// TODO(lukesandberg): switch to relative once next is compatible.
SourceMapSourceType::TurbopackUri
SourceMapSourceType::RelativeUri
});
if next_mode.is_production() {
builder = builder
......@@ -1149,8 +1148,7 @@ pub async fn get_server_chunking_context(
builder = builder.source_map_source_type(SourceMapSourceType::AbsoluteFileUri);
} else {
builder = builder
// TODO(lukesandberg): switch to relative once next is compatible.
.source_map_source_type(SourceMapSourceType::TurbopackUri)
.source_map_source_type(SourceMapSourceType::RelativeUri)
.chunking_config(
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
ChunkingConfig {
......
......@@ -196,9 +196,16 @@ function getSourcemappedFrameIfPossible(
}
sourceMapPayload = maybeSourceMapPayload
try {
// Pass the source map URL as the second parameter so that the consumer
// can resolve relative paths in the source map's `sources` array.
// This is a guess! Turbopack places .map files as siblings to the chunks so this is sufficient to compute
// relative paths but is actually wrong (the chunk and sourcemap have different content hashes).
// We are using the node API to read the sourcemap and it doesn't give us access to the URI.
const sourceMapURL = sourceURL + '.map'
sourceMapConsumer = new SyncSourceMapConsumer(
// @ts-expect-error -- Module.SourceMap['version'] is number but SyncSourceMapConsumer wants a string
sourceMapPayload
sourceMapPayload,
// @ts-expect-error: our typings don't include this parameter but it is here.
sourceMapURL
)
} catch (cause) {
// We should not log an actual error instance here because that will re-enter
......
......@@ -111,9 +111,6 @@ export function getPrerenderOutput(
)
.replace(/at \d+ \(/, replaceNumericModuleId)
.replace(/digest: '\d+'/, "digest: '<error-digest>'")
// TODO(veil): Bundler protocols should not appear in stack frames.
.replace('webpack:///', 'bundler:///')
.replace('turbopack:///[project]/', 'bundler:///')
lines.push(convertModuleFunctionSequenceExpression(line))
}
......
......@@ -8,7 +8,6 @@ function normalizeCliOutput(output: string) {
stripAnsi(output)
// TODO(veil): Should not appear in sourcemapped stackframes.
.replaceAll('webpack:///', 'bundler:///')
.replaceAll('turbopack:///[project]/', 'bundler:///')
.replaceAll(/at [a-zA-Z] \(/g, 'at <mangled> (')
)
}
......@@ -55,9 +54,9 @@ describe('app-dir - server source maps', () => {
} else {
if (isTurbopack) {
// TODO(veil): Sourcemap names
// TODO(veil): relative paths
// TODO(veil): relative paths in webpack
expect(normalizeCliOutput(next.cliOutput)).toContain(
'(bundler:///app/rsc-error-log/page.js:4:17)'
'(app/rsc-error-log/page.js:4:17)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'' +
......@@ -106,10 +105,10 @@ describe('app-dir - server source maps', () => {
// TODO(veil): Sourcemap names
// TODO(veil): relative paths
expect(normalizeCliOutput(next.cliOutput)).toContain(
'(bundler:///app/rsc-error-log-cause/page.js:2:17)'
'(app/rsc-error-log-cause/page.js:2:17)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'(bundler:///app/rsc-error-log-cause/page.js:7:17)'
'(app/rsc-error-log-cause/page.js:7:17)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'' +
......@@ -230,7 +229,7 @@ describe('app-dir - server source maps', () => {
// TODO(veil): Sourcemap names
// TODO(veil): relative paths
expect(normalizeCliOutput(next.cliOutput)).toContain(
'(bundler:///app/ssr-error-log-ignore-listed/page.js:9:17)'
'(app/ssr-error-log-ignore-listed/page.js:9:17)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'\n' +
......@@ -295,7 +294,7 @@ describe('app-dir - server source maps', () => {
// TODO(veil): Sourcemap names
// TODO(veil): relative paths
expect(normalizeCliOutput(next.cliOutput)).toContain(
'at <unknown> (bundler:///app/rsc-error-log-ignore-listed/page.js:8:17)'
'at <unknown> (app/rsc-error-log-ignore-listed/page.js:8:17)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'' +
......@@ -528,7 +527,7 @@ describe('app-dir - server source maps', () => {
'' +
'\nError: module-evaluation' +
// TODO(veil): Turbopack internals. Feel free to update. Tracked in https://linear.app/vercel/issue/NEXT-4362
'\n at module evaluation (bundler:///app/module-evaluation/module.js:1:22)'
'\n at module evaluation (app/module-evaluation/module.js:1:22)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain(
'' +
......
......@@ -67,7 +67,7 @@ describe('build-output-prerender', () => {
// TODO(veil): Why is the location incomplete unless we enable --no-mangling?
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at c (bundler:///app/client/page.tsx:4:28)
at c (app/client/page.tsx:4:28)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
......@@ -181,32 +181,62 @@ describe('build-output-prerender', () => {
})
it('shows all prerender errors with readable stacks and code frames', async () => {
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at Page (bundler:///app/client/page.tsx:4:28)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` before accessing either uncached data (e.g. \`fetch()\`) or Request data (e.g. \`cookies()\`, \`headers()\`, \`connection()\`, and \`searchParams\`). Accessing random values synchronously in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (bundler:///app/server/page.tsx:13:27)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
if (isTurbopack) {
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at Page (app/client/page.tsx:4:28)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` before accessing either uncached data (e.g. \`fetch()\`) or Request data (e.g. \`cookies()\`, \`headers()\`, \`connection()\`, and \`searchParams\`). Accessing random values synchronously in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (app/server/page.tsx:13:27)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
} else {
// TODO(veil): Bundler protocols should not appear in stackframes.
expect(getPrerenderOutput(next.cliOutput)).toMatchInlineSnapshot(`
"Error: Route "/client" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at Page (webpack:///app/client/page.tsx:4:28)
2 |
3 | export default function Page() {
> 4 | return <p>Current time: {new Date().toISOString()}</p>
| ^
5 | }
6 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/client" in your browser to investigate the error.
Error occurred prerendering page "/client". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route "/server" used \`Math.random()\` before accessing either uncached data (e.g. \`fetch()\`) or Request data (e.g. \`cookies()\`, \`headers()\`, \`connection()\`, and \`searchParams\`). Accessing random values synchronously in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at Page (webpack:///app/server/page.tsx:13:27)
11 | await cachedDelay()
12 |
> 13 | return <p>Random: {Math.random()}</p>
| ^
14 | }
15 |
To get a more detailed stack trace and pinpoint the issue, start the app in development mode by running \`next dev\`, then open "/server" in your browser to investigate the error.
Error occurred prerendering page "/server". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
> Export encountered errors on following paths:
/client/page: /client
/server/page: /server"
`)
}
})
})
})
......@@ -386,11 +416,7 @@ function getPrerenderOutput(cliOutput: string): string {
if (foundPrerenderingLine && !line.includes('Generating static pages')) {
lines.push(
line
.replace(/at \w+ \(.next[^)]+\)/, 'at x (<next-dist-dir>)')
// TODO(veil): Bundler protocols should not appear in stackframes.
.replace('webpack:///', 'bundler:///')
.replace('turbopack:///[project]/', 'bundler:///')
line.replace(/at \w+ \(.next[^)]+\)/, 'at x (<next-dist-dir>)')
)
}
}
......
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