-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Debugging vite+vue+typescript using HMR is broken. Breakpoint on incorrect line numbers #33
Comments
This is a very serious issue! It is not jus TS, but for JS also. |
Update: In my case this is only a problem for Single File Components. Debugging in typescript files seems to have correct line numbers. It does suggest that the problem is in sourcemap generation for SFCs. |
me too,I wonder how soon the author team can solve |
Started playing around with Vite+Vue tonight - and came across this error. I just don't get it - how can anyone use Vite when it's impossible to attach a debugger (Chrome // VSCode)....? This seems like a critical show stopper bug issue to me. Hope it gets fixed soon. Will have to revert to Webpack for now. |
@ngjermundshaug yes indeed, it leads me to think that it either isn't used a lot or only hits a few people. |
me too, I can't debugging in chrome dev tool. It's a serious bug. |
Got same issue with vite + typescript + react + mobx, but only happened in some ts file. |
can't believe this bug has been hanging for nearly half years and nothing changed |
Agreed, it is unfortunate as apart from debugging not working I love vite. Maybe it is time to look at alternatives. |
I too am affected by this issue. I walked through the sequence below while playing around with this problem today. I was working on private code but suspect the same holds on a simpler repo. Specific test:
So, between steps 1 and 9, the source code is the exact same, but the resulting breakpoint trigger location has changed when VS Code triggers. I don't know the internals well enough, but it seems that Vite is capable of handling the mapping correctly on first load, but then something changes post HMR. In particular, the thing that changes is independent of the actual source since my source files are identical at start and end. I'm purely guessing, but it seems that the source map is missing the last hop to get from the If there are any pointers on how to debug these various steps, I'd give it a whirl. Unfortunately, I don't know the debugging process or source maps well enough to reason it out otherwise. That is, I'd love to help, but it's not clear how. |
Based on issue vitejs/vite#673, it seems that disabling HMR works around the issue.
It looks like the choice is to have HMR or debugging, you cannot have both. If you don't mind restarting the dev server after each edit, this might be a viable (although somewhat tedious) workaround. |
I made an attempt at upgrading from vue2 to vue3+vite a few days ago. Debugging worked fine for a few hours - until it suddenly didn't. Haven't been able to quite pinpoint what causes it yet. BUT I have been able to make it work in Firefox (with HMR) by:
You can also press Ctrl-P in Debugger window in Firefox and open the component/file there - but you'll see several files (same name, different url) but make sure you take the cachebusted version (the one with ?t=123123123123). |
I'm having same problem with vite. Not able to debug. :( |
I have the same issue (breakpoints are off by 10-20 lines depending on the file). It's not happening on all the files which is super strange. I'm trying to find a pattern. Disabling HRM does not solve anything, but disabling sourcemaps is the only way I can debug something. |
Update on my bug. I've analyze the sourcemaps for a simple file (http://sokra.github.io/source-map-visualization/#custom is a very awesome tool). Every file containing an import of react has bad sourcemaps, without react it's fine. Those file contains generated code to enable HMR:
from what I've seen sourceMaps are not taking into account those lines and it offset the sourceMaps by something like 12 to 15 lines. This is my observation, I might be wrong, but removing the generated code HMR setup fixes the source maps completely. I'm trying to disable HMR to see source maps, but setting: server: { hmr: false }, does not do anything. This code is still being generated and source maps are off. |
This is a major deal breaker issue for our team and is blocking our migration from Webpack. I don't understand how such a critical bug can go unresolved for so long, did we miss a workaround or something? Any feedback from the vite.js team would be much appreciated. |
Found my issue! I was using vite-plugin-require because we had a couple of them. I manage to remove all except one so I use the exclude option:
When analysing source maps with this plugin, they come out quite differently. Some newline are inserted that are messing up source maps. You can repro with a very simple project I hope this solve the issue for a bunch of you! Cheers! |
I have exactly the same issue, I can't use |
Any update on this? I can connect the debugger to the compiled JS files in vscode, but unable to link it all the way to the original TS files. |
I have same issue.const Button = defineComponent({
setup(props, { slots }) {
console.log('*****slots')
console.log(slots)
const { default: _default, left, right } = slots
//NOTE CAN NOT REACH HERE
debugger
return () => (
<button style={style}>
{left ? left() : null}
{_default ? _default() : 'BUTTON'}
{right ? right() : null}
</button>
)
},
}) |
Looks like no one cares to fix this. |
This is also a problem in react (see vitejs/vite-plugin-react#23), so maybe it should be on a higher level than this plugin? |
That worked for me. I'm using Vite 4.x and React with Typescript. Until that change, Vite was unusable for me. I was very close to switching. Thanks |
similar problem here:
It seems all the above behaviors are due to the out of sync source maps @yyx990803 |
@cryptoGF Yes I think that Vite doesn't do HMR. Source maps are correct until a HMR takes place. As @matija2209 confirmed, disabling mhr does often make debugging workable. |
这问题一年过去了还没解决吗?官方为什么没人说明一下呢? |
我的项目也出现了相同问题;经过多次测试。发现使用了element-plus全局自动按需引入后会出现这个问题;具体是因为unplugin-vue-components、unplugin-auto-import这两个包。当安装了这两个包后发现node_modules里面会多出几个webpack相关的包; |
I can't speak for everyone because my setup is slightly unusual, but I'm able to debug a Vue 3 SFC TS application in VSCode using the Firefox extension. Here is my raw config (note that my frontend project is a subfolder of the workspace folder). My config is unusual because in development, a Django application serves a HTML which includes scripts from another virtual host, where Vite is running.
This is what it should look like if I adjust the paths to those of a regular setup
|
So the key is to use |
@khaledOghli Thanks for the tip but I don't think this solves the issue. @Tobiaqs interesting. I'm no longer using vue because of this issue, but maybe someone else can test this? |
正常指, 可以在chrome中断点了? |
我说一下自己的分析: 我使用的vite+react+ts的项目
所以要接这个问题, 就是怎么把old文件上的断点信息,带到新的文件上面来. I'll give my own analysis: I'm using a project with vite+react+ts. After running the project, what we see in the source files in Chrome is actually the compiled JS code. When we set a breakpoint in it, it is set on this file. how? |
To clarify, debugging is currently working fine with Chrome Devtools' debugging for the following cases:
It only breaks after HMR if the debugging is done by launching via VSCode. So the solution is to prefer Chrome's native debugger instead of VSCode's debugger. You'll also find that Chrome's native debugger is more reliable and much faster. As for the VSCode issue, it is not really caused by Vue or plugin-vue, but an incompatibility between VSCode's debugger and how Vite HMR works. I'm not sure if this is something we can fix - if anything, this seems to be something VSCode should be fixing since Vite is working fine with Chrome's native debugger as far as I can tell. |
Hmm, not saying you're wrong, but this is a bit of a stretch. Saying that 'since it works in chrome it can't be vite' has a few shortcomings.
I think it is incorrect to close this issue as nothing has been resolved. |
I encountered this too, and I think the issue is "content validation" in the launch.json: {
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Chrome",
"url": "http://localhost:8080",
"enableContentValidation": false
}
]
} Here's what the documentation for
@hspaay, can you check if this fixes debugging for you too? |
Describe the bug
Trying to debug a vite+vue+ts app doesn't work for me. As soon as HMR runs the vscode debugger no longer stops on breakpoints. Possible the sourcemap gets out of sync.
In addition, chrome devtools doesn't show the source code but the hard to read minified code.
Similar bugs:
Line numbers in TypeScript broken for Chrome/VSCode debugging vite#5834 although this report mentions that "the application does indeed break at the expected moment, and both Chrome Debugger and VSCode highlight the same (correct) lines", which is different behavior than mentioned in this report.
[@vitejs/plugin-react] VS Code Breakpoints do not get hit after first fast refresh in plugin-react in new project vite-plugin-react#23 might be the same issue but uses react. It does mention that a browser refresh fixes it, but does not mention the problem that setting breakpoints elsewhere in the code is no longer always possible.
The issue at hand seems that after HMR the sourcemaps get messed up. I suspect that the issue goes deeper than that as I have a more complex app where the source map remains incorrect even after clearing the cache. Anyway lets fix get the simple case addressed.
Reproduction
Expected behavior: vscode stops at the breakpoint
Actual behavior: breakpoint is ignored
After reloading the browser (F5) the breakpoint works again in this simple example until the code changes.
To spice it up a bit, replace the line with count++ to invoke a function 'incrementCount as follows:
and add this function in the script section:
Repeat the test, this time setting the breakpoint in the function.-> this works as expected
Now try to set the breakpoint on the line with the button click. vscode will add a breakpoint in HelloWorld.vue?import=&t=1638336354075 (or something like it).
Hit the count button again... => expected behavior, the debugger stops. Actual behavior: the debugger does not stop.
Hit F5 in the browser. => expected behavior, the browser refreshes and shows the app. Actual behavior, the debugger stops somewhere randomly.
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: