Skip to content
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

ssrFixStacktrace generates incorrect stack traces in Node 12 #2265

Closed
Rich-Harris opened this issue Feb 26, 2021 · 0 comments · Fixed by #2266
Closed

ssrFixStacktrace generates incorrect stack traces in Node 12 #2265

Rich-Harris opened this issue Feb 26, 2021 · 0 comments · Fixed by #2266

Comments

@Rich-Harris
Copy link
Contributor

Describe the bug

Calling ssrFixStacktrace(error) where the original stack trace goes through line 1 or 2 (where the line number is 1-based) will result in this error if you're using Node 12:

TypeError: Line must be greater than or equal to 1, got -1

That's because of this line:

line: Number(line) - 2,

In Node 12, stack traces are accurate, as though the anonymous function wrapper didn't exist:

const fn = new Function(`throw new Error('nope');n//# sourceURL=test.js`);
fn();

// in Node 12
// Uncaught Error: nope
//    at eval (test.js:1:7)

// in Node 13 and later
// Uncaught Error: nope
//    at eval (test.js:3:7)

Because of that, subtracting 2 is unnecessary. But it is necessary in 13 and later.

If the original doesn't go through line 1 or 2, no error will be raised, but the sourcemapped stack trace will be incorrect.

Reproduction

https://github.com/Rich-Harris/vite-repro-ssr-fix-stacktrace

System Info

  • vite version: 2.0.3
  • Operating System: MacOS
  • Node version: 12
  • Package manager (npm/yarn/pnpm) and version: npm 7.0.3
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant