Skip to content

Commit 5c5f82c

Browse files
KaelWDbluwy
andauthored
fix: improve CJS warning trace information (#17926)
Co-authored-by: bluwy <[email protected]>
1 parent 15871c7 commit 5c5f82c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/vite/index.cjs

+15-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ function warnCjsUsage() {
3838
}
3939
}
4040
const yellow = (str) => `\u001b[33m${str}\u001b[39m`
41-
const log = process.env.VITE_CJS_TRACE ? console.trace : console.warn
42-
log(
41+
console.warn(
4342
yellow(
4443
`The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.`,
4544
),
4645
)
46+
if (process.env.VITE_CJS_TRACE) {
47+
const e = {}
48+
const stackTraceLimit = Error.stackTraceLimit
49+
Error.stackTraceLimit = 100
50+
Error.captureStackTrace(e)
51+
Error.stackTraceLimit = stackTraceLimit
52+
console.log(
53+
e.stack
54+
.split('\n')
55+
.slice(1)
56+
.filter((line) => !line.includes('(node:'))
57+
.join('\n'),
58+
)
59+
}
4760
}

0 commit comments

Comments
 (0)