-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Source map don't refresh after source change/save & node restart. Attaching/re-attaching to Meteor.js server (meteor debug) #7117
Comments
@johnf76 Since I do not (yet) have any experience with debugging meteor with VS Code, I could only speculate what the problem might be (and I will stay away from that until I know more details). (BTW, a quick Internet search showed that debugging meteor server side is possible with VS Code: https://forums.meteor.com/t/using-visual-studio-code-for-meteor-development/21058) First some facts about node debugging in VS Code:
What does step 6 ("Break out of meteor instance (ctrl-c)") from above mean? Does it kill the underlying node.js? |
@weinand Thanks for the quick response and information. Regarding being able to use VSCode for server side debugging, yes, I am successfully debugging meteor applications and it works very well for the most part, I apologize I didn't explain that well. From what I notice (and reading your bullet points), it seems like maybe the cache is persisting somehow? When I'm debugging (both node in debug mode & vscode attached), I detach the debugger, then kill the node process and restart (meteor rebuilds the application and runs "node /path/to/my/app.js debug"). From that point only re-attaching the VSCode debugger after closing & restarting VSCode will have the code changes reflected. Regarding #6, yes, running "meteor debug" basically builds the applications then executes "node /path/to/my/app.js debug", for example below is the process, the screen wrapping makes it kind of hard to read. When breaking out (ctrl-c), it's just killing the node process.
Also, one thing to note which realized I didn't mention & don't know if it could be part of the issue, meteor runs an old version of node (v0.10.43). Their next release will be updating to v4+ (don't know the exact version). Thanks, John |
@johnf76 since I'm the author of node-debug, I'm pretty sure that no cache is persisted between debug sessions ;-) Yes, node v0.10.43 is indeed very old but I don't think that is the source of your problem. So let's analyse what you said about the initial problem: A regular source map is a mapping between a generated JavaScript file and one or more source files that got transpiled into the generated JavaScript. Only a source map with "inlined source" can lead to the issue that you are seeing: "the source map shows the source before modification". In this case the original source files are inlined into the source maps when the source map is generated. In this case the mapping and the source are always in synch but they only reflect what's being executed if the source map has been regenerated after you have edited the source. Could you please try this:
Please let me know what you find. |
Thanks @weinand, I have verified as you stated. It does show "inlined content from source map" in the header. I was able to locate the source map and verified that the "app.js.map" was specified in the node source on the last line.
Last line of Verifying the source map is recreated:
I stopped the debugger, and re-attached, it paused at the new debugger line, however as reported, it's showing the source prior to the change. I can make several changes and stop/restarts of the meteor application and VSCode debugger will only show the original source from when the debugger was initially attached. Also, just to mention for completeness, if I completely stop the meteor process (break out of "meteor debug" which runs "node debug") and change source, then restart it via "meteor debug" (vs just changing and saving the source in which meteor (if running) catches the source change and rebuilds automatically as shown above). It actually deletes the "app" directory, then recreates is and generates the new app.js & app.js.map files. The behaviour with VSCode is the same either way, but wanted to mention just in case there might be something to it.
Also, just a quick side question, should the F9 break statement work when attaching and debugging a node app? I've found when attaching they don't work, but debugger statements. If there's anything else I can help with please let me know, thanks for your help! |
@johnf76 thanks for this excellent and detailed investigation. That made things clearer and sparked my interest to install meteor and play with it. I could easily reproduce the problem and it is not a caching problem of node-debug, but seems to be a bug in VSCode. The correct inlined source contents is fetched, but the old content is shown. Fix will appear in Alpha next week. Breakpoints: in theory it should be possible to use breakpoints instead of debugger statements. But after analysing the generated sourcemaps and meteor's bootstrap code, I realized that this whole setup is highly adapted to the Chrome Dev tools. Making it work in VSCode requires quite some work. Could you get breakpoints to work in node-inspector? I couldn't either. |
Thank you for your help @weinand, much appreciated! I just tried using breakpoints in the chrome node-inspector, same here, breaks do not work. I don't understand enough about how it all works, is the break line issue more of a problem with the generated source maps? Is something to possibly report as an issue w/ Meteor or is more of an item that can only be enhanced to work on the node-inspector / VSCode end? The debugger statements work, so it's not a big deal, but it is convenient to not have to type debugger; all over the place :) Not quite the place for asking, but curious since you played with it for a few, what are your initial thoughts of Meteor? The biggest issue for me so far is that I really want to use TypeScript and it's not a trivial task to setup with Meteor & React, dynamic types is JS just don't feel right. :) Just curious, what kind of JS frameworks do you/others on the team like to use? Anyway, thank you again, I'm looking forward to the update. |
@johnf76 thanks for trying the breakpoints with node-inspector. This confirms that the Meteor generated source maps are somewhat unusual. So it would be great if you could report an issue w/ Meteor to get at least their opinion on that matter. I did a very superficial exploration of Meteor, so I do not yet have deep insights. Meteor seems to be very smart and tries to help with an edit/compile/debug/go workflow. I did not fully understand what they do, but one thing that surprised me was that I saw 5 threads in the VS Code node debugger. Yes, I implemented the support for multiple threads in node-debug but I never saw any node.js based system making use of this. The problem with all this magic is that it is sometimes a bit tricky to add other technologies (e.g. TypeScript) to this. So Meteor watches for file changes (edits) and builds the application, but how to integrate the TypeScript transpiler into this build process requires some insights that I do not yet have. |
@johnf76 VS Code alpha has the fix now. |
Steps to Reproduce:
{
"name": "Attach Server",
"type": "node",
"request": "attach",
"port": 5858,
"address": "127.0.0.1",
"restart": true,
"sourceMaps": true,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
ISSUE:
9. The program WILL pause at the new debugger location and correctly run the code changes, however the source map shows the source before modification (obviously making debugging impossible). To correct and get the source map recreated/updated I need to closing VSCode and re-starting, then re-attaching the debugger.
Side Issue: The 'F9' debug breaks don't work at all when attaching to meteor application line above, I have to use 'debugger' statements. It'd be so much more convenient use pause with F9 breaks.. F9 works just fine when launching a straight node application, not sure what the difference is or if I'm doing something wrong?
BTW, VSCode kicks ass, thanks for building this, it's so fast and nice to work with.. I've been using Webstorm for node/meteor for years, I switched, the speed of the application is night & day (debugging is where is really hit home though (except for having to type 'debugger' all over :)).
The text was updated successfully, but these errors were encountered: