Skip to content

Commit

Permalink
fix: improve CJS warning trace information (#17926)
Browse files Browse the repository at this point in the history
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
  • Loading branch information
KaelWD and bluwy authored Sep 2, 2024
1 parent 15871c7 commit 5c5f82c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/vite/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,23 @@ function warnCjsUsage() {
}
}
const yellow = (str) => `\u001b[33m${str}\u001b[39m`
const log = process.env.VITE_CJS_TRACE ? console.trace : console.warn
log(
console.warn(
yellow(
`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.`,
),
)
if (process.env.VITE_CJS_TRACE) {
const e = {}
const stackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 100
Error.captureStackTrace(e)
Error.stackTraceLimit = stackTraceLimit
console.log(
e.stack
.split('\n')
.slice(1)
.filter((line) => !line.includes('(node:'))
.join('\n'),
)
}
}

0 comments on commit 5c5f82c

Please sign in to comment.