You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally reported at vitest-dev/vitest#5569. I think I've seen 2-3 similar reports in the past too.
When a file is SSR transformed in Vite, debuggers like Chrome Dev tools and VSCode are unable to "step into" functions that are imported via named imports. In practice this means stopping debugger in line 3 and pressing "step into" button of debuggers in the example below.
1|import{add}from"./math.ts";2|3|add(1,2);
Debugger should stop at line 1 or 2, but instead it stops at 7.
Video demonstrating step-into issue with Vite SSRvite-step-into.webm
I think this has something to do with the way Vite SSR transforms import into import() and saves the results into single variable. In the reproduction setup I've created "Vite simulation", where SSR transformed file is loaded directly into Node.
In this example "step into" works correctly on lines 11 and 15. If Vite was able to destructure the named imports of __vite_ssr_exports__ into separate variables, I think debuggers would work just fine. But this would break ESM live bindings.
1|globalThis.__vite_ssr_exports__={};2|debugger;3|4|awaitimport("./transpiled.js");5|const{ add, multiply }=globalThis.__vite_ssr_exports__;6|7|// Incorrect position when "step into"8|globalThis.__vite_ssr_exports__.add(1,2);9|10|// Correct position when "stepinto"11|add(1,2);12|13|// Same here14|globalThis.__vite_ssr_exports__.multiply(1,2);15|multiply(1,2);16|
Video showing how lines 11 and 15 work correctlynode-step-into.webm
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
In the source map there is a weird mapping into the position where debugger stops. I tested if removing this with magic-string + @ampproject/remapping helps, but debugger is still working the same.
I guess we need to tell the debugger that the property access of __vite_ssr_exports__.add should be ignored when stepping. But I'm not sure if there's a way to do that.
One idea would be to avoid the property access with a helper function and map that helper function to somewhere and set that in x_google_ignoreList.
constaccess=(obj,key)=>obj[key]// the helper functionaccess(__vite_ssr_exports__,'add')(1,2)
Describe the bug
Originally reported at vitest-dev/vitest#5569. I think I've seen 2-3 similar reports in the past too.
When a file is SSR transformed in Vite, debuggers like Chrome Dev tools and VSCode are unable to "step into" functions that are imported via named imports. In practice this means stopping debugger in line 3 and pressing "step into" button of debuggers in the example below.
Debugger should stop at line 1 or 2, but instead it stops at 7.
Source map of the
math.ts
in reproduction: https://evanw.github.io/source-map-visualization/#NDI2AGZ1bmN0....Video demonstrating step-into issue with Vite SSR
vite-step-into.webm
I think this has something to do with the way Vite SSR transforms
import
intoimport()
and saves the results into single variable. In the reproduction setup I've created "Vite simulation", where SSR transformed file is loaded directly into Node.In this example "step into" works correctly on lines 11 and 15. If Vite was able to destructure the named imports of
__vite_ssr_exports__
into separate variables, I think debuggers would work just fine. But this would break ESM live bindings.Video showing how lines 11 and 15 work correctly
node-step-into.webm
Reproduction
https://github.com/AriPerkkio/vite-ssr-transform-sourcemaps-issue
Steps to reproduce
See README https://github.com/AriPerkkio/vite-ssr-transform-sourcemaps-issue/blob/main/README.md.
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: