-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add new sourceRootDir
setting
#31873
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
Comments
Currently we treat {
"compilerOptions": {
"sourceMap": true,
"sourceRoot": "https://foo.com/debug/sourcemaps/"
}
} However, we could change this to identify absolute paths and URLs and keep those verbatim. We don't currently use the @aleclarson: You can work around this by specifying the following in your tsconfig.json: {
"include": ["src"],
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"sourceMap": true,
"sourceRoot": "../src"
}
} @RyanCavanaugh, @DanielRosenwasser: I am concerned this could be a breaking change for some users. Do we want to pursue changing the behavior of |
This is an issue for anyone using a monorepo with Typescript. Unless the definition of a function/class/type is directly in the index.ts file of the referenced module, then "go to definition" functionality lands inside a .d.ts file instead. As far as a breaking change, could this be resolved by detecting the value is a URL and then NOT putting relative paths into the map files? |
This also breaks debugging in, at least, VSCode as it is unable to resolve the source -> JS mappings when the map files have a "sourceRoot". We have had to remove "sourceRoot" from the project being debugged (we have yet to evaluate any other side effects) but we cannot debug other modules from within the same mono-repo which are being used by that project. Can we get confirmation of a work-around or that this will actually be in 4.1.0? This issue has been pushed off for over a year and it's crippling to our development team. |
I discussed this with the team. To support this without introducing a breaking change we will have to add a
|
It appears the "fix" is not to use "sourceRoot" when sources are on the local filesystem and only use it when source will be hosted. VSCode now correctly finds the original source both when editing and when debugging. The documentation lead us to believe that we had to have "sourceRoot" set in order for mappings to be correct but it's actually the opposite. |
@RyanCavanaugh this issue keeps being postponed for a long time. Is there anyway to prioritise it 😃 ? It is blocking us in a monorepo with Bazel and I believe it is also affecting others in the same setup too. |
I will restate, one last time: we removed "sourceRoot" from our configuration and the files all generated with the correct roots. It is evident that "sourceRoot" should only be used when hosting your map files on a web-site. We have a monorepo with 60+ packages. Most of those packages have the following structure:
This works for debugging, VSCode link following, and everything else we've tried. Our initial issue was a misunderstanding of when to use "sourceRoot" which appears to only be when you're placing the .map, .d.ts, etc. files in a completely separate location. I can't think of a reason to do that except to host the files on a web-site. IMO - the only issue here is documentation. |
@raijinsetsu thanks for the inputs here. I actually know what you mentioned and confirm this. However our use case is different. When using Bazel, the compilation happens in a sandbox in a temporary location. The build contents are then located outside of the repo and symlinks are created. I really need the option to control the 'sourceRoot' content, which we have at the moment, but the relative path is not correctly calculated for nested files/folders under the package root. We need to patch that behaviour on |
Would that not be fixed by putting the symlink in the same relative location to the src folder as it is within the sandbox? Sandbox: Repo: |
@raijinsetsu we don't have that level of control on Bazel and honestly I dont want to create a new symlink for each package target folder. Developing on windows is already slower and symlinks/junctions there are always painful. What we really need is that sourceRoot behaves like |
sourceRootDir
setting
This one's been around a long while and we haven't yet seen the quantity of feedback that would justify further complicating the file resolution process. |
@mistic just curious if you found any workaround? Also in need for relative workspace source root paths. |
@tinganho I endup implementing a custom Typescript types summariser with sourcemaps support that runs over the |
Thanks @mistic for your answer. @RyanCavanaugh do you accept PR on this or still awaiting feedback? I think this blocks Bazel IDE debugging adoption for TypeScript atm. Also on the last point on @rbuckton proposal:
First, I have hard time seeing a use case for verbatim |
fwiw, my initial thought was that |
This would be really needed when working with a monorepo utilising workspaces. Consider the scenario where Whenever any other package uses Without Right now the only solution is to set However, how such configuration is supposed to be manageable? We cannot commit local absolute paths into a repo, it would collide with everyone else's setup. Another approach could be to use the ... As long as you don't use references, because than this setup will be broken for all the dependent packages (even if the So if someone is using some external monorepo tools, like Nx or so, they can manually configure appropriate scripts for each packages and rely on the tool to trigger rebuild of dependent packages. But with references it is not suitable. Right now as a workaround we have a root level script in place that auto-generates a We need a solution that is not copied verbatim, like
Indeed we have to acknowledge that in this case the sourcemaps inside |
TypeScript Version: 3.5.1
Search Terms: sourceRoot, sources, sourcemap
Code
Create a module like:
src/nested/foo.ts
Use the following
tsconfig.json
with tsc:Expected behavior:
Inside
nested/foo.js.map
, thesourceRoot
should be../src/
instead ofsrc/
. Otherwise, the paths in thesources
array cannot be found.Actual behavior:
The
sourceRoot
issrc/
regardless of nesting.Playground Link: N/A
Related Issues: None
The text was updated successfully, but these errors were encountered: