Skip to content

Sourcemap - names array empty for all files #9627

Open

Description

@slaneyrw

TypeScript Version: 1.8.34.0
Module System: AMD
ECMAScript Version: ECMAScript 5
VS 2015 Update 3

All of my map files have the names array empty. I would expect that to have been populated.
This has been an issue with VS2015 with all updates

Code

class HomeIndex {

    someVar: number;

    constructor() {
        this.someVar = 0;
    }

    onLoad = () => { 
    };

    dispose() {
    };

}

export = HomeIndex;

Generated map

{
  "version": 3,
  "file": "Index.js",
  "sourceRoot": "",
  "sources": [ "Index.ts" ],
  "names": [],
  "mappings": ";;IAAA;QAII;YAIA,WAAM,GAAG;YACT,CAAC,CAAC;YAJE,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACrB,CAAC;QAKD,2BAAO,GAAP;QACA,CAAC;;QAEL,gBAAC;IAAD,CAAC,AAdD,IAcC;IAED,OAAS,SAAS,CAAC"
}

Expected behavior:
names array should contain values for members and variables
Actual behavior:
names array empty

Activity

  1. mhegazy commented on Jul 11, 2016

    @mhegazy
    Contributor

    this is not a supported feature at the moment. the compiler does not emit names to the source map output.

  2. nojvek commented on Jan 23, 2018

    @nojvek
    Contributor

    Is this something that is relatively easy to fix as part of sourcemap emit step ?

  3. yudhistira-arya commented on Jan 23, 2020

    @yudhistira-arya

    Is this issue still being actively looked at?

  4. grzegorzjudas commented on Apr 24, 2020

    @grzegorzjudas

    So I just configured debugging in VSCode and was really amazed by how great it works... until I noticed the variable names that is. Came here after research on why, when I put a breakpoint I see the transpiled variable names instead of the original ones, even though I have the source maps working. I can't use the original names in the debug console either, which breaks the whole experience.

    I'd say it's a pretty important, but I have no concept on how complex it is to implement, so I'll just leave it here in hope it'll increase the priority.

  5. axelcostaspena commented on May 26, 2020

    @axelcostaspena

    Also without the knowledge about the current implications of fixing this, but the reality is that this breaks 25% of typescript debugging on IntelliJ IDEA, VS Code, etc, whenever you need to evaluate code with imported symbols.

    https://youtrack.jetbrains.com/issue/WEB-43973
    https://stackoverflow.com/questions/59864978/typescript-undefined-constant-during-debugging-session

  6. RayzRazko commented on Jun 6, 2020

    @RayzRazko

    This is extremely frustrating. Sometimes it makes it almost impossible to debug the code. I'm surprised this issue is not prioritized.

  7. FrancescoBorzi commented on Jun 12, 2020

    @FrancescoBorzi

    Confirmed. This is extremely important.

  8. Yehonal commented on Jun 12, 2020

    @Yehonal

    I ended-up here from this stackoverflow issue:

    https://stackoverflow.com/questions/56669155/debugging-vs-code-with-typescript-shows-transpiled-variable-names-instead-of-rea

    I literally cannot debug my typescript node application because exported variables are not recognized by the debugger.

    And this issue exists since 2016! How could it be?

    That's the evidence:

    image

  9. 8 remaining items

  10. BenMoses commented on Mar 3, 2021

    @BenMoses

    Alos having this issue. I am unable to implement Webpack into my project to work around this bug. This seems like it shouldn't be too complicated to fix / implement, am I being too naive?

  11. Christilut commented on Mar 21, 2021

    @Christilut

    Same problem here. Very hard to use the debug console.

    As a (painful) workaround, you can see what actual variable names you should use in the debugger, eg instead of Foo.bar() it might be _Foo.Foo.bar()

  12. pavel-luhin commented on Apr 1, 2021

    @pavel-luhin

    Notice same issue. Global config variables almost always undefined in debugger, and cannot ‘Evaluate Expression’ in WebStorm IDE.

  13. bingtimren commented on Jun 23, 2021

    @bingtimren

    Same issue. This makes debugging with IDE awful. Wish there's a solution to this.

  14. vkria-sftsrv commented on Jul 23, 2021

    @vkria-sftsrv

    Same issue. It causes ReferenceError: <var> is not defined in WebStorm in Evaluate Expression window...

  15. georgyfarniev commented on Sep 18, 2021

    @georgyfarniev

    Ryan Cavanaugh (@RyanCavanaugh) Wesley Wigham (@weswigham) Alan Agius (@alan-agius4) hello, is there any plans to include this issue in the roadmap? I also find it extremely frustrating.

    At least, can you give me a brief insight how difficult will it be to solve in case if I will try to create PR for this issue?

    Wish you to have a nice weekend.

  16. scpedicini commented on May 22, 2022

    @scpedicini

    2022, any updates on this? Best practices in terms of getting this working without being forced to use webpack in webstorm? I use parcel, is it possible to get this working using that bundler?

  17. imfycc commented on May 22, 2022

    @imfycc
  18. spyro2000 commented on Mar 13, 2023

    @spyro2000

    It's been 7 years now.

    SEVEN.
    YEARS.

    And it's still not possible to debug/evaluate an imported function in typescript. I just can't believe this has never been fixed. It's just broken. :(

  19. segevfiner commented on Mar 13, 2023

    @segevfiner

    I think esbuild does output the names array, you can try using it instead of tsc, or use it via tsup.

  20. espenja commented on Oct 27, 2023

    @espenja

    I hit this issue today, and got it working by using tsup/esbuild
    Importantly, treeshake had to be set to false, or variables would all be undefined again.

    Here's the tsup config I ended up with:

    defineConfig({
      outDir: DIST_FOLDER,
      entry: glob
        .sync("src/functions/*/index.ts", {
          cwd: path.resolve(__dirname, "../"),
          absolute: true
        })
        .map(globbify),
      keepNames: true,
      sourcemap: true,
      minify: false,
      format: "cjs",
      target: "node20",
      platform: "node",
    }
  21. pflannery commented on Jun 13, 2024

    @pflannery

    I have this issue too. Im using version 5.4.5. It only happens to me when compiling from esm to cjs.

    Esm named imports get wrapped into a generated object (here) which then causes issues with debugging the original source code.

    Example:

    // esm
    import { workspace } from 'vscode'
    const codeLensEnabled = vscode.workspace.getConfiguration().get('editor.codeLens')
    
    // translates to 
    const vscode_1 = require("vscode"); // debuggers can't resolve the generated name
    const codeLensEnabled = vscode_1.workspace.getConfiguration().get('editor.codeLens')

    One workaround is to use import * as {alias}

    e.g.

    // esm
    import * as vscode from 'vscode'
    const codeLensEnabled = vscode.workspace.getConfiguration().get('editor.codeLens');
    
    // translates to
    //....emit helper code omitted here....
    const vscode = __importStar(require("vscode")); // debuggers work with this
    const codeLensEnabled = vscode.workspace.getConfiguration().get('editor.codeLens');

    But this isn't ideal and limits esm import features.

    It would be great if typescript could output a left-hand object destructor (when the target supports destructoring)

    const { workspace } = require("vscode");
    const codeLensEnabled = workspace.getConfiguration().get('editor.codeLens')

    It's either that or typescript will need to add the original names[] and their associated mappings: "..." in to the source map.
    I'm guessing the source map update would most likely need to be put somewhere here?

    Going to take someone with good experience of the typescript source code to fix this.

  22. matthewdowell commented on Mar 21, 2025

    @matthewdowell

    Please let there be some traction on this. Such a painful debugging experience 😔. I really don't want to switch IDE's but might have to.

  23. bingtimren commented on Mar 21, 2025

    @bingtimren

    Lately I have been using Javascript Debug Terminal and TSX, zero setup and just works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions