-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Wrong line numbers in stacktraces in dev mode on console, in IntelliJ/WebStorm and VSCode #10138
Comments
The issue could be fixed by changing
and then changing
There's no need for a Proxy object. Note that If I find the time I'd might prepare a PR. |
I'm running into this as well. As I'm converting a project from purely client-side Svelte to SvelteKit, there are lots of references to browser-only objects like |
Why is this problem not a bigger issue? I've notiiced the problem for quite a while and it takes a lot of time figuring out what is wrong when something fails. I tried to reproduce and as @dmoebius shows, It does not take much to replicate it. On long files its even harder to find the problem. |
So in order to fix that and to know on which line I have an error (such a basic programming feature), I have to download entire SvelteKit sources, make these edits and then recompile the thing? I just use SvelteKit as npm package, how would I will do all this high level stuff... |
You could use patch-package to patch this changes during |
Btw. FYI: This whole issue was created for SvelteKit 1.20.x, Svelte 3.x (!), Vite 4.3.x. I didn't have the time to check whether this issue occurs with the newest versions. Might be worth a try. |
Latest Vite, Svelte (4.x) and SvelteKit set share the same issue. |
Here's the patch file, for sveltekit v1.20.1 at least. Maybe it works for newer versions, too. (PS: for some reason GitHub doesn't let me attach the *.patch file directly; I had to zip it first. 🤷 ) Unzip it, put it into your workspace |
I recreated the patch for the latest sveletkit (v1.25.0). It works better on a simplified error like above, but on a more complex project it was still off by some lines. |
Hi all |
This is it. I've tested on Node 16, 18, 20 and the result is still the same.
Exactly right. We can safely use Sorry this flew under the radar. Thank you to the great work by the issue author.
@benquan can you help provide a reproducible for this? I'm not sure how to diagnose this (and it might then be an issue with vite's ssrFixStacktrace). |
The fix in #10138 (comment) only fixed some server stack traces, but I think errors occurring during module importing have the wrong line numbers as well. You can see the wrong line numbers in the server console and the vite HMR overlay in the browser. // _bad.js
const bad = foo().toUpperCase();
export default bad;
function foo() {} <script>
// +page.svelte
import bad from './_bad.js';
</script>
<h1>{bad}</h1> |
The bug is back on the latest packages versions. |
Please create a new issue with a reproduction so that we diagnose the cause of the issue. |
Describe the bug
In Dev mode, SvelteKit modifies the line numbers of server stacktraces by calling
fix_stack_trace()
, which in turn callsvite.ssrRewriteStacktrace(stack)
. This is done by wrapping the Error object in a Proxy (methodhandle_error_and_jsonify()
inkit/src/runtime/server/utils.js
). This works in some environments, e.g. StackBlitz, but not on the console or IntelliJ/WebStore or VSCode.Reproduction
src/routes/+page.server.ts
with the following content:npm run dev
on the console and open http://localhost:5173/You'll get the following stacktrace:
Notice that the line numbers are wrong:
+page.server.ts:4:9
Correct:
+page.server.ts:2:9
@sveltejs/kit/src/runtime/server/page/load_data.js:57:41
Correct:
load_data.js:51:41
(as of @sveltejs/kit 1.20.2)@sveltejs/kit/src/runtime/server/page/index.js:150:41
Correct:
index.js:141:19
(as of @sveltejs/kit 1.20.2)Notice that the line numbers are not just off by a fixed offset.
The same happens if you use the IDEs IntelliJ/Webstorm or VSCode to execute
rpm run dev
.Logs
No response
System Info
Severity
annoyance
Additional Information
The culprit is in https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/server/utils.js#L98 line 98ff:
This wraps the error in a Proxy that fixes the stacktrace when the stack property is accessed. Problem: when running on the console or in IDEs such as IntelliJ or VSCode, then those environments never access
error.stack
directly to print the stacktrace! I don't know which mechanism they use to output it, but I debugged it and although the proxy gets created, the proxyget
method never gets called. It is indeed called in e.g. StackBlitz, because when you try to do the same there, you'll get correct stacktraces, e.g.: https://stackblitz.com/edit/sveltejs-kit-template-default-htvqfu?file=src%2Froutes%2F%2Bpage.server.tsThe regression has been introduced by this commit on Jan 13.
Btw,
fix_stack_trace()
in turn callsvite.ssrRewriteStacktrace(stack)
inkit/src/exports/vite/dev/index.js
:AFAICT Vite's
ssrRewriteStacktrace(stack)
is no longer the right way to fix an ssr stacktrace. It has been obsoleted byssrFixStacktrace(error)
(see vitejs/vite#7045), which should be used instead, because it takes care that the line numbers don't get mangled if you accidentally call the method twice; they memoize if it has been called already.Prior work
I checked very thoroughly for previous issues about this issue. It is not related to:
The text was updated successfully, but these errors were encountered: