Skip to content

Commit abc4c6e

Browse files
committed
fix: clean up webpack eval wrapper in stack traces
1 parent e69adf1 commit abc4c6e

File tree

4 files changed

+30
-306
lines changed

4 files changed

+30
-306
lines changed

packages/next/next-dev-server.webpack-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ module.exports = ({ dev }) => {
194194
path: path.join(__dirname, 'dist/compiled/dev-server'),
195195
filename: '[name].js',
196196
libraryTarget: 'commonjs2',
197+
// Use absolute paths in source maps so error formatting can compute correct relative paths
198+
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
197199
},
198200
devtool: 'source-map',
199201
optimization: {

packages/next/src/server/dev/node-stack-frames.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { parse } from 'next/dist/compiled/stacktrace-parser'
22
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
3+
import path from 'path'
4+
import url from 'url'
35
import {
46
decorateServerError,
57
type ErrorSourceType,
@@ -29,6 +31,25 @@ function getFilesystemFrame(frame: StackFrame): StackFrame {
2931
return f
3032
}
3133

34+
/**
35+
* Convert a file path to a path relative to the current working directory.
36+
*/
37+
function toRelativePath(filePath: string): string {
38+
if (filePath.startsWith('file://')) {
39+
try {
40+
filePath = url.fileURLToPath(filePath)
41+
} catch {
42+
// Invalid file URL, use as-is
43+
}
44+
}
45+
46+
if (path.isAbsolute(filePath)) {
47+
return path.relative(process.cwd(), filePath)
48+
}
49+
50+
return filePath
51+
}
52+
3253
export function getServerError(error: Error, type: ErrorSourceType): Error {
3354
if (error.name === 'TurbopackInternalError') {
3455
// If this is an internal Turbopack error we shouldn't show internal details
@@ -54,7 +75,8 @@ export function getServerError(error: Error, type: ErrorSourceType): Error {
5475
.map((f) => {
5576
let str = ` at ${f.methodName}`
5677
if (f.file) {
57-
let loc = f.file
78+
// Convert to relative path for cleaner output
79+
let loc = toRelativePath(f.file)
5880
if (f.lineNumber) {
5981
loc += `:${f.lineNumber}`
6082
if (f.column) {

packages/next/src/server/lib/bytecode-cache.ts

Lines changed: 0 additions & 289 deletions
This file was deleted.
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
/**
2-
* Start Server Entry Point with Bytecode Caching
2+
* Start Server Entry Point for Bundled Dev Server
33
*
4-
* This is the entry point for the dev server that uses V8 bytecode caching
5-
* to speed up loading of the bundled dev server on subsequent startups.
4+
* This module provides a unified entry point that can load either the bundled
5+
* or unbundled dev server based on environment configuration.
66
*
77
* Environment variables:
8-
* NEXT_DISABLE_BYTECODE_CACHE=1 - Disable bytecode caching
9-
* NEXT_USE_UNBUNDLED_SERVER=1 - Use unbundled server instead
8+
* NEXT_USE_UNBUNDLED_SERVER=1 - Use unbundled server instead (for development)
109
*/
1110

1211
import path from 'path'
13-
import { isBytecodeCacheEnabled, loadWithBytecodeCache } from './bytecode-cache'
1412

1513
// Determine which server to load
1614
const useBundled = process.env.NEXT_USE_UNBUNDLED_SERVER !== '1'
17-
const useBytecodeCache = isBytecodeCacheEnabled() && useBundled
1815

1916
const serverPath = useBundled
2017
? path.join(__dirname, '../../compiled/dev-server/start-server.js')
2118
: path.join(__dirname, './start-server.js')
2219

2320
// Load the server module
24-
let serverModule: typeof import('./start-server')
25-
26-
if (useBytecodeCache) {
27-
// Use bytecode caching for faster subsequent loads
28-
serverModule = loadWithBytecodeCache(serverPath)
29-
} else {
30-
// Regular require
31-
serverModule = require(serverPath)
32-
}
21+
const serverModule: typeof import('./start-server') = require(serverPath)
3322

3423
// Re-export everything from the server module
3524
export const { startServer, getRequestHandlers } = serverModule

0 commit comments

Comments
 (0)