Repository navigation
VSCode doesn't respect sourceRoot in declarationMaps #25322
Description
Activity
Michael Aird (@michaelaird) what command line options are you compiling with (your tsconfig and/or command line settings) when you're using
vscode?michaelaird commented
on Jun 29, 2018 AuthorMore actionsWhen I compile from the command line using tsc I’m only using -p to point at the tsconfig file. I think the issue is VSCode ignoring sourceRoot. Not the difference in output. (edited because autocorrect on my phone converted tsconfig to "taco gig" :) )Hmmmmm the only differences I see are that we set
sourceRootto""and each of the paths in sources to be relative to the sourcemap directly (so../../Dependency/BaseClass.ts), while your other sourcemap tool has removed the common path part from all the sources (../../Dependency) and placed it as thesourceRoot(leaving the source filename as justBaseClass.ts).AFAIK these should function identically. - in both cases applying the sourceRoot to the sourcemaps's dir and joining the filename should yield the same final path.
If anything,
"sourceRoot":"../../Dependency"from gulp-sourcemaps is missing a tailing slash 🤷♂️But anyway - I think I'm going to need more to reproduce your issue; both of those sourcemaps should work fine. Also it'd be nice if you could check if the issue still repros when you use
typescript@next's tsserver, since we have made a bunch of fixes to the sourcemaped LS calls recently.I am seeing the same problem with TS 2.9.2, the sourcemaps for *.d.ts files, generated by gulp-sourcemaps are unusable in VS Code (latest insiders), since the navigation is completely disabled.
In the latest TS@next, the navigation is restored, but I end up in the *.d.ts file, NOT the actual *.ts file.
The difference between the tsc's generated maps and the ones generated via gulp-sourcemaps, is that:
- TSC: sourceRoot: "", sources:["../../../../name.ts"]
- gulp-sourcemaps: sourceRoot: "../../", sources: ["../../name.ts"]
So, the end-result should be the same, but it is not, VS Code properly works with the first version.
Wesley Wigham (@weswigham) I can share a small repro project. where should I send it?
If public, here. Failing that, mhegazy at Microsoft dot com is a decent option. In any case, in pretty sure I know the issue. In
sourcemapDecoder.ts, where it saysconst sourceRoot = map.sourceRoot || currentDirectorytoPathneeds to be called onmap.sourceRootif present, to ensure we always have a rooted absolute path.Wesley Wigham (@weswigham) I sent a small repro to Mohamed Hegazy (@mhegazy) .
Edit: attaching the repro here because MS's email server is too smart.
DeclarationMaps.zip- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jul 20, 2018 This still fails when project references are used.
Here's a repro:
DeclarationMaps.zipWesley Wigham (@weswigham) can you take a look
Michael Aird (@michaelaird) The
sourceRootgenerated bygulp-sourcemapsis off. It's emitting"sourceRoot":"../../DeclarationMaps/Dependency", when it should just be"sourceRoot":"../../Dependency", since the file is in/Output/jsand the sources are in/Dependency. It looks like your gulp task is moving around the outdir in a way it doesn't respect?Yep. you're right. i'll fight with gulp-sourcemaps to sort out the relative paths. sorry about the false alarm!
Michael Aird (@michaelaird) have you figured out how to get
declarationMapworking with gulp-sourcemaps? Could you share a repo where you used it?- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version: 2.9.2
I'm running into an issue when building declaration maps with gulp-typescript/gulp-sourcemaps.
the output of gulp-sourcemaps does this:
where the output of tsc does this:
Expected behavior:
VSCode should respect sourceRoot and find the source code
Actual behavior:
VSCode can't find the declaration when navigating.
I can provide a simple repro if needed.
Note
In VSCode, when you try to navigate it does nothing. In VS 15.8.0 Preview 3 it navigates to the d.ts file.