-
-
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
Line numbers in browser stack trace are off by 2 for .js files #3371
Comments
I have considered that Vite may be to blame in some way. I do not have more hours to spare for debugging this in the few coming days, so I'm posting this hoping for comments from someone who is more familiar with the Svelte Kit architecture than I am. Any feedback is welcome! If no one else wants to try, I may have time to come back to this sometime in February. |
Yes, this is almost certainly a bug in Vite. No worries that you don't have time to investigate a fix for this, but would you be able to file a bug for this in that repo? Tips on doing that here: https://github.com/sveltejs/kit#bug-reporting There appears to be a related issue in the Vite issue tracker: vitejs/vite#5834 |
Tested this on latest SvelteKit, and it seems to be fixed now. Capitalize test:
On line 1:
However on reload:
It might be an accidental double stack trace fix at kit/packages/kit/src/vite/dev/index.js Line 159 in c556511
and kit/packages/kit/src/vite/dev/index.js Line 368 in c556511
|
* tidy up * reset stack traces to avoid double fix - closes #3371 * use options.dev instead of __SVELTEKIT_DEV__ so that testing against src still works * weird
Describe the bug
When displaying stack traces in the browser, the line numbers are sometimes off by 2. See reproduction repo below.
capitalize-test: always off by 2 in browser
Try opening capitalize-test (probably http://localhost:3000/capitalize-test) in your browser. The stacktrace output in the browser will always be as follows (note the line 2 in
/src/routes/_capitalize.js:2:22
, while the line actually occurs on line 4 in the file):The output in the terminal from the dev server correctly displays line 4 in the stack trace:
Try refreshing a couple of times. It should not make a difference to the server or browser output.
on-line-1-test:
off by 2 in browser on first load
Try opening on-line-1-test (probably http://localhost:3000/on-line-1-test) in your browser. The stacktrace output in the browser is as follows on the first try:
The dev server gives roughly the same output.
Works if you refresh the page or open it in a new tab
If you refresh the page, you get an error message in the browser that looks correct to me (and no output from the dev server), but varies slightly by browser.
Firefox
Chrome
Safari
This applies to all supported node versions
I have tried this with node versions 14, 16 and 17. The behavior is exactly the same in all cases.
Reproduction
git clone https://github.com/Vages/offset-demo.git cd offset-demo npm install npm run dev
Navigate to the routes
capitalize-test
andon-line-1-test
, probably found at these URLs:Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
Possibly related issue
I was able to find this Vite PR (from Rich Harris, accidentally – or perhaps not), which compensates for stack trace offsets in node versions later than 13: vitejs/vite#2266 I thought there could possibly be something different about node versions 14 and later and tried running the following script (named
offset.js
) in node versions 12 through 16.The output was consistent from versions 14 and on:
If you put
offset.js
in a folder with a package.json containing the following,... you get the following stack trace instead:
The text was updated successfully, but these errors were encountered: