-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhelpful error.stack
in browser mode
#7370
Comments
I don't think vitest/packages/browser/src/client/tester/logger.ts Lines 40 to 47 in b526896
For example, when // example.test.ts
import { it } from 'vitest';
import { testTrace } from "./example";
it("repro", () => {
testTrace();
})
// example.ts
export type Dummy = {
}
export function testTrace() {
testTraceInner();
}
function testTraceInner() {
console.trace("repro")
}
We'll probably need to obtain all source files in Then back to |
@hi-ogawa, is it possible to somehow rewrite A common way I use to get the current stack is by using function getCurrentStack(): string {
return new Error().stack;
} This currently only works outside of browser mode. |
It would require guessing stack trace by parsing any string passed from |
Describe the bug
In browser mode,
error.stack
is not pointing to the correct line and column where the error was declared.For example, the following code
outputs
Notice how each line starts with
http://
and points to the built file. Trying to open the first link in a browser is unsuccessful:http://localhost:63315/home/diegoaquino/www/vitest-issues/vitest-browser-error-stack/example.test.ts?import&browserv=1738024191536:3:17
Also, the line and column numbers (
3:17
) are incorrect. Maybe the source map is not being considered?Compared to other tracing alternatives,
console.trace()
appears to work fine, even though the stack trace is not as complete as when browser mode is disabled:outputs
I frequently rely on stack traces for debugging. It would be really useful if
error.stack
pointed to the correct line and column in browser mode. This problem does not occur when it is disabled (e.g.environment: 'node'
).Please let me know if this is a configuration issue on my part!
Reproduction
https://github.com/diego-aquino/vitest-browser-error-stack
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: