Skip to content

Commit 1ee4dfd

Browse files
eps1lonstipsan
authored andcommitted
Run with --enable-source-maps by default in next dev (vercel#71820)
We already create server source maps in dev by default, so we should make use of them. To opt-out, run `next dev --disable-source-maps` instead. Our internal `next-no-sourcemaps` script is now defunct.
1 parent d459209 commit 1ee4dfd

File tree

13 files changed

+332
-54
lines changed

13 files changed

+332
-54
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"prepublishOnly": "turbo run build",
5252
"lint-staged": "lint-staged",
5353
"next-with-deps": "./scripts/next-with-deps.sh",
54-
"next": "cross-env NEXT_TELEMETRY_DISABLED=1 node --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
55-
"next-no-sourcemaps": "cross-env NEXT_TELEMETRY_DISABLED=1 node --trace-deprecation packages/next/dist/bin/next",
54+
"next": "cross-env NEXT_TELEMETRY_DISABLED=1 NODE_OPTIONS=\"--trace-deprecation --enable-source-maps\" next",
55+
"next-no-sourcemaps": "echo 'No longer supported. Use `pnpm next --disable-source-maps` instead'; exit 1;",
5656
"clean-trace-jaeger": "node scripts/rm.mjs test/integration/basic/.next && TRACE_TARGET=JAEGER pnpm next build test/integration/basic",
5757
"debug": "cross-env NEXT_TELEMETRY_DISABLED=1 node --inspect --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
5858
"postinstall": "node scripts/git-configure.mjs && node scripts/install-native.mjs",

packages/next/src/bin/next.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ program
172172
'-H, --hostname <hostname>',
173173
'Specify a hostname on which to start the application (default: 0.0.0.0).'
174174
)
175+
.option(
176+
'--disable-source-maps',
177+
"Don't start the Dev server with `--enable-source-maps`.",
178+
false
179+
)
175180
.option(
176181
'--experimental-https',
177182
'Starts the server with HTTPS and generates a self-signed certificate.'

packages/next/src/cli/next-dev.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { flushAllTraces, trace } from '../trace'
4040
import { traceId } from '../trace/shared'
4141

4242
export type NextDevOptions = {
43+
disableSourceMaps: boolean
4344
turbo?: boolean
4445
turbopack?: boolean
4546
port: number
@@ -267,6 +268,12 @@ const nextDev = async (
267268
delete nodeOptions['max_old_space_size']
268269
}
269270

271+
if (options.disableSourceMaps) {
272+
delete nodeOptions['enable-source-maps']
273+
} else {
274+
nodeOptions['enable-source-maps'] = true
275+
}
276+
270277
if (nodeDebugType) {
271278
const address = getParsedDebugAddress()
272279
address.port = address.port + 1

run-tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ ${ENDGROUP}`)
480480
// unset CI env so CI behavior is only explicitly
481481
// tested when enabled
482482
CI: '',
483+
// But some tests need to fork based on machine? CI? behavior differences
484+
// Only use read this in tests.
485+
// For implementation forks, use `process.env.CI` instead
486+
NEXT_TEST_CI: process.env.CI,
483487

484488
...(options.local
485489
? {}

test/development/middleware-errors/index.test.ts

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
assertNoRedbox,
44
check,
55
getRedboxSource,
6+
retry,
67
} from 'next-test-utils'
78
import stripAnsi from 'strip-ansi'
89
import { nextTestSetup } from 'e2e-utils'
@@ -31,23 +32,22 @@ describe('middleware - development errors', () => {
3132

3233
it('logs the error correctly', async () => {
3334
await next.fetch('/')
34-
const output = stripAnsi(next.cliOutput)
35-
await check(() => {
36-
if (isTurbopack) {
37-
expect(stripAnsi(next.cliOutput)).toMatch(
38-
/middleware.js \(\d+:\d+\) @ __TURBOPACK__default__export__/
39-
)
40-
} else {
41-
expect(stripAnsi(next.cliOutput)).toMatch(
42-
/middleware.js \(\d+:\d+\) @ default/
43-
)
44-
}
45-
46-
expect(stripAnsi(next.cliOutput)).toMatch(/boom/)
47-
return 'success'
48-
}, 'success')
49-
expect(output).not.toContain(
50-
'webpack-internal:///(middleware)/./middleware.js'
35+
36+
await retry(() => {
37+
expect(stripAnsi(next.cliOutput)).toContain('boom')
38+
})
39+
// TODO: assert on full, ignore-listed stack
40+
expect(stripAnsi(next.cliOutput)).toContain(
41+
isTurbopack
42+
? '\n ⨯ middleware.js (3:15) @ __TURBOPACK__default__export__' +
43+
'\n ⨯ Error: boom' +
44+
'\n at __TURBOPACK__default__export__ (./middleware.js:3:15)'
45+
: '\n ⨯ middleware.js (3:15) @ default' +
46+
'\n ⨯ boom' +
47+
'\n 1 |' +
48+
'\n 2 | export default function () {' +
49+
"\n> 3 | throw new Error('boom')" +
50+
'\n | ^'
5151
)
5252
})
5353

@@ -79,13 +79,20 @@ describe('middleware - development errors', () => {
7979

8080
it('logs the error correctly', async () => {
8181
await next.fetch('/')
82-
await check(
83-
() => stripAnsi(next.cliOutput),
84-
new RegExp(`unhandledRejection: Error: async boom!`, 'm')
82+
83+
await retry(() => {
84+
expect(stripAnsi(next.cliOutput)).toContain(
85+
'unhandledRejection: Error: async boom!'
86+
)
87+
})
88+
// TODO: assert on full, ignore-listed stack
89+
expect(stripAnsi(next.cliOutput)).toContain(
90+
isTurbopack
91+
? 'unhandledRejection: Error: async boom!\n at throwError ('
92+
: 'unhandledRejection: Error: async boom!' +
93+
'\n at throwError (webpack-internal:///(middleware)/./middleware.js:8:11)' +
94+
'\n at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(middleware)/./middleware.js:11:5)'
8595
)
86-
// expect(output).not.toContain(
87-
// 'webpack-internal:///(middleware)/./middleware.js'
88-
// )
8996
})
9097

9198
it('does not render the error', async () => {
@@ -112,17 +119,37 @@ describe('middleware - development errors', () => {
112119

113120
it('logs the error correctly', async () => {
114121
await next.fetch('/')
115-
// const output = stripAnsi(next.cliOutput)
116-
await check(() => {
117-
expect(stripAnsi(next.cliOutput)).toMatch(
118-
/middleware.js \(\d+:\d+\) @ eval/
122+
123+
await retry(() => {
124+
expect(stripAnsi(next.cliOutput)).toContain('Dynamic Code Evaluation')
125+
})
126+
// TODO: assert on full, ignore-listed stack
127+
if (isTurbopack) {
128+
// Locally, prefixes the "test is not defined".
129+
// In CI, it prefixes "Dynamic Code Evaluation".
130+
expect(stripAnsi(next.cliOutput)).toContain(
131+
'\n ⚠ middleware.js (3:22) @ __TURBOPACK__default__export__' +
132+
'\n ⨯ middleware.js (4:9) @ eval'
119133
)
120-
expect(stripAnsi(next.cliOutput)).toMatch(/test is not defined/)
121-
return 'success'
122-
}, 'success')
123-
// expect(output).not.toContain(
124-
// 'webpack-internal:///(middleware)/./middleware.js'
125-
// )
134+
}
135+
expect(stripAnsi(next.cliOutput)).toContain(
136+
isTurbopack
137+
? '\n ⨯ Error: test is not defined' +
138+
'\n at eval (./middleware.js:4:9)' +
139+
'\n at <unknown> (./middleware.js:4:9'
140+
: '\n ⨯ Error [ReferenceError]: test is not defined' +
141+
'\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' +
142+
'\n at eval (webpack://_N_E/middleware.js?3bcb:4:8)'
143+
)
144+
expect(stripAnsi(next.cliOutput)).toContain(
145+
isTurbopack
146+
? "\n ⚠ Error: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
147+
'\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' +
148+
'\n at __TURBOPACK__default__export__ (./middleware.js:3:22)'
149+
: '\n ⚠ middleware.js (4:9) @ eval' +
150+
"\n ⚠ Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
151+
'\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation'
152+
)
126153
})
127154

128155
it('renders the error correctly and recovers', async () => {
@@ -150,22 +177,18 @@ describe('middleware - development errors', () => {
150177

151178
it('logs the error correctly', async () => {
152179
await next.fetch('/')
153-
const output = stripAnsi(next.cliOutput)
154-
await check(() => {
155-
if (isTurbopack) {
156-
expect(stripAnsi(next.cliOutput)).toMatch(
157-
/middleware.js \(\d+:\d+\) @ \[project\]\/middleware\.js \[middleware\] \(ecmascript\)/
158-
)
159-
} else {
160-
expect(stripAnsi(next.cliOutput)).toMatch(
161-
/middleware.js \(\d+:\d+\) @ <unknown>/
162-
)
163-
}
164-
expect(stripAnsi(next.cliOutput)).toMatch(/booooom!/)
165-
return 'success'
166-
}, 'success')
167-
expect(output).not.toContain(
168-
'webpack-internal:///(middleware)/./middleware.js'
180+
181+
await retry(() => {
182+
expect(stripAnsi(next.cliOutput)).toContain(`Error: booooom!`)
183+
})
184+
// TODO: assert on full, ignore-listed stack
185+
expect(stripAnsi(next.cliOutput)).toContain(
186+
isTurbopack
187+
? '\n ⨯ middleware.js (3:13) @ [project]/middleware.js [middleware] (ecmascript)' +
188+
'\n ⨯ Error: booooom!' +
189+
'\n at <unknown> ([project]/middleware.js [middleware] (ecmascript) (./middleware.js:3:13)'
190+
: '\n ⨯ Error: booooom!' +
191+
'\n at <unknown> (webpack://_N_E/middleware.js'
169192
)
170193
})
171194

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
pnpm-lock.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { run } from 'internal-pkg'
2+
3+
function logError() {
4+
const error = new Error('Boom')
5+
console.error(error)
6+
}
7+
8+
export default function Page() {
9+
run(() => logError())
10+
return null
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client'
2+
import { run } from 'internal-pkg'
3+
4+
function logError() {
5+
const error = new Error('Boom')
6+
console.error(error)
7+
}
8+
9+
export default function Page() {
10+
run(() => logError())
11+
return null
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
function logError() {
4+
const error = new Error('Boom')
5+
console.error(error)
6+
}
7+
8+
export default function Page() {
9+
logError()
10+
return null
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function run(fn) {
2+
return fn()
3+
}

0 commit comments

Comments
 (0)