-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Better Support for Source Breakpoints when output is in different folders #6915
Comments
actually, could this be globbed please? If my TS file is in a sub-directory, it doesn't seem to be able to find the breakpoints either. |
+1 I have source maps in some modules in the node_modules folder, and VSCode is unable to find them. If I place a breakpoint in a .ts file in a node_modules module, the vscode-node-debug debugger is unable to automatically resolve the source map location. However, if I instead place the breakpoint in the corresponding .js file, the source map resolves based on the sourceMappingURL, and the breakpoint is hit in the .ts file. This is a somewhat counterintuitive workaround. Being able to specify multiple outDirs looks like it might fix the problem. |
I've had to solve this by compiling ts->js/map in the same folder, you can then entirely hide the js/map files that have a corresponding ts file next to them. .vscode/settings.json: {
"files.exclude": {
"**/*.js": {"when": "$(basename).ts"},
"**/*.map": {"when": "$(basename).map"}
}
} This seems like the only way to reliably have VSCode map from js to ts, when execution moves over multiple folders, and make your project tree look sane. |
I think this is related to a similar problem I am having. My projects file structure is as follows: project
With my setup I can add breakpoints to the app.ts and everything works as expected however if i add a breakpoint to nestedFile.ts get the dreaded "Breakpoint ignored because..." error. I'm assuming that until outDir can take an array of directories as a value this is going to be a problem and the only realistic work around for larger project is as @MeirionHughes suggests? |
I've updated the issue so its a bit more clear. |
I think that while being able to pass outDir an Array is a solution, its probably not the best solution. Glad you changed the title of the issue. :) |
@kineticfaction your structure should work (and I even have an automatic test for exactly that case). Set |
I agree, we need a way to specify more than one However, in the discussions/comments that are following I see some speculation and misconceptions about how things work. So here are some clarifications: Source mapping always involves two directions: mapping source to generated code and mapping generated code back to source. JavaScript source maps only cover the second case: "mapping generated code back to source". The other direction must be either derived from the first direction (exhaustive search), or by explicitly configuring it in the launch.json. Let's start with how the "mapping source to generated code" is configured with the The Now let's look into the other direction "mapping generated code back to source": For this the VS Code debugger needs a way to find the originating source if a breakpoint has been hit in some generated JavaScript file. By convention there is a URL at the end of the generated code file that points to the source map (*.js.map) or contains the source map inlined as a data url:
The URL can either point to a location on disk (an absolute or relative file URL), or it can be an http URL that points to some remote file. This means that VS Code makes no assumption about where the source map is located but just follows the URL in the generated code (so the statement from some comment above "VS Code fails to match up map/js in sub-folders" is not correct). Just make sure that the URL is correct and VS Code will be able to find the source map. I recommend to either keep the source maps side by side with the generated code which results in a very simple (relative) URL or to use inlined source maps. With inlined source maps the URL is a data URL that contains the map. This is less error prone, but since the data URL uses base64 encoding, it is more difficult to see what's in the source map. The next step in "mapping generated code back to source" is in the source map itself. Here the entries in the So in @kineticfaction's structure from above the entries in the {
"file": "nestedFile.js",
"sources": [
"../../maps/source/routes/nestedFile.ts"
]
} and {
"file": "app.js",
"sources": [
"../maps/source/app.ts"
]
} Or if a common prefix of the paths is extracted into a separate {
"file": "nestedFile.js",
"sourceRoot": "../../maps/source",
"sources": [
"routes/nestedFile.ts"
]
} and {
"file": "app.js",
"sourceRoot": "../maps/source",
"sources": [
"app.ts"
]
} |
Doesn't appear to work properly for me when I have subfolders. I have some code in |
@MeirionHughes you have to set |
sorry yes... typo. it is set to dist. In my case it definitely matches up the root folder though: (./src to ./dist) |
@MeirionHughes and it must be an absolute path, e.g. |
Yes sorry; its exactly that. :P |
ahh I may know why... I think my sourceRoot is wrong in the output. the relative path from the sub folders is wrong. I'm setting it like:
|
Can you please add |
Sorry @weinand, you are correct with the same folder structure plus correct sourceRoot; it does work. So we're left with the original issue (support for multiple outDir folders). |
@MeirionHughes great to hear that sourcemaps works for you for the one-outDir case. I'm planning to add globbing support for |
Thanks Andre I'll take a look this evening once i get out of the office |
@weinand Yep works perfectly as expected. |
@kineticfaction thanks a lot for verifying that your setup works. |
How about debugging codes generated by ts-node? I'm using mocha to run test.ts:
ts-node will compile test.ts to test.js which locates in a temp folder. The folder structure in source can never match the structure in the generated code. I can't debug for test.ts if I set the sourceMap option enabled. |
Steps to Reproduce:
Given:
"outDir": "${workspaceRoot}/dist"
then:
break-point will resolve for foo.ts
break-point will not resolve for foo.spec.ts
use-case:
I'm outputting source code to both a "dist" and "spec" folder; based on whether the file is
*.spec.ts
or not. As a result I have two locations for source mappings. In order to be able to assign breakpoints in both the.ts
and.spec.ts
files I must specify an outDir for VS Code's launch.json. Unfortunately, it does not support multiple directories so I can only pick one at the moment.The text was updated successfully, but these errors were encountered: