Skip to content

VSCode doesn't respect sourceRoot in declarationMaps #25322

Description

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:

{"version":3,"sources":["BaseClass.ts"],"names":[],"mappings":"AAAA,kBAAU,UAAU,CACpB;IACI;QAEI,OAAO,CAAC,UAAU,CAAS;;2BAOb,SAAS,EAAK,MAAM;QAK3B,WAAW,IAAI,IAAI;KAI7B;CACJ","file":"Dependency.d.ts","sourceRoot":"../../Dependency"}

where the output of tsc does this:

{"version":3,"file":"Dependency.d.ts","sourceRoot":"","sources":["../../Dependency/BaseClass.ts"],"names":[],"mappings":"AAAA,kBAAU,UAAU,CACpB;IACI;QAEI,OAAO,CAAC,UAAU,CAAS;;2BAOb,SAAS,EAAK,MAAM;QAK3B,WAAW,IAAI,IAAI;KAI7B;CACJ"}

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.

Activity

  1. weswigham commented on Jun 29, 2018

    @weswigham
    Member

    Michael Aird (@michaelaird) what command line options are you compiling with (your tsconfig and/or command line settings) when you're using vscode?

  2. michaelaird commented on Jun 29, 2018

    @michaelaird
    Author
  3. weswigham commented on Jul 6, 2018

    @weswigham
    Member

    Hmmmmm the only differences I see are that we set sourceRoot to "" 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 the sourceRoot (leaving the source filename as just BaseClass.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.

  4. vvs commented on Jul 8, 2018

    @vvs

    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:

    1. TSC: sourceRoot: "", sources:["../../../../name.ts"]
    2. 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.

  5. michaelaird commented on Jul 10, 2018

    @michaelaird
    Author

    Wesley Wigham (@weswigham) I can share a small repro project. where should I send it?

  6. weswigham commented on Jul 10, 2018

    @weswigham
    Member

    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 says const sourceRoot = map.sourceRoot || currentDirectory toPath needs to be called on map.sourceRoot if present, to ensure we always have a rooted absolute path.

  7. michaelaird commented on Jul 17, 2018

    @michaelaird
    Author

    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

  8. michaelaird commented on Jul 26, 2018

    @michaelaird
    Author

    This still fails when project references are used.

    Here's a repro:
    DeclarationMaps.zip

  9. mhegazy commented on Jul 26, 2018

    @mhegazy
    Contributor

    Wesley Wigham (@weswigham) can you take a look

  10. weswigham commented on Jul 26, 2018

    @weswigham
    Member

    Michael Aird (@michaelaird) The sourceRoot generated by gulp-sourcemaps is off. It's emitting "sourceRoot":"../../DeclarationMaps/Dependency", when it should just be "sourceRoot":"../../Dependency", since the file is in /Output/js and the sources are in /Dependency. It looks like your gulp task is moving around the outdir in a way it doesn't respect?

  11. michaelaird commented on Jul 26, 2018

    @michaelaird
    Author

    Yep. you're right. i'll fight with gulp-sourcemaps to sort out the relative paths. sorry about the false alarm!

  12. domoritz commented on Jul 7, 2021

    @domoritz

    Michael Aird (@michaelaird) have you figured out how to get declarationMap working with gulp-sourcemaps? Could you share a repo where you used it?

  13. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions