Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Sourcemap resolution not working for sourcemaps in node_modules folders. #82

@shoerob

Description

@shoerob

I have a few node_modules I am including in a main project that include .js, .d.ts, .js.map, and .ts files. The reason for this is that I'd like to be able to debug the main project, as well as the modules which it heavily depends on via npm linking the modules during development. The structure of the fully built project is as follows:

project/src/index.ts
project/lib/index.d.ts
project/lib/index.js
project/lib/index.js.map
project/node_modules/mymodule/src/someclass.ts
project/node_modules/mymodule/lib/someclass.d.ts
project/node_modules/mymodule/lib/someclass.js
project/node_modules/mymodule/lib/someclass.js.map

Note that "project/src/index.ts" imports "someclass" in the following way:
import { someclass } from 'mymodule/lib/someclass';

My launch.json has the following configuration:

{
    "name": "Launch",
    "trace": "all",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/src/index.ts",
    "stopOnEntry": false,
    "args": [],
    "cwd": "${workspaceRoot}",
    "preLaunchTask": "build",
    "runtimeExecutable": null,
    "runtimeArgs": [
        "--nolazy"
    ],
    "env": {
        "NODE_ENV": "development"
    },
    "externalConsole": true,
    "sourceMaps": true,
    "outDir": "${workspaceRoot}/lib"
},

When launching the application, any breakpoints I set in "project/src/index.ts" are successfully detected and hit. Any breakpoints I set in "project/node_modules/mymodule/src/someclass.ts" are noted in VSCode as "breakpoint ignored because generated code not found". However, when I set a breakpoint in "project/node_modules/mymodule/lib/someclass.js" (the javascript file), the breakpoint is set, and when it is hit, the corresponding .ts file is displayed in VSCode.

In looking at the source code for vscode-node-debug, it looks like sourcemaps are resolve in one of the following ways when a breakpoint is set in a .ts file (please correct me if I am wrong):

  • try to find a sourcemap relative to the .ts file
  • try to find an already loaded sourcemap by matching the .ts file to the sources array.
  • try to find a sourcemap in the outDir specified in the configuration.

Based on this, I can understand why the sourcemap for "someclass.ts" does not get resolved. I can also understand why adding the breakpoint to "someclass.js" causes the sourcemap to resolve successfully. This is because the .js file contains a sourceMappingURL which points to the correct location, and removes the guesswork.

That being said, I am wondering if this falls under the category of bug or feature request. Should I be able to debug typescript w/sourcemaps in the node_modules subfolders by adding breakpoints to those typescript files? Or - should I be using a different project configuration altogether to make debugging work properly? I don't think my project setup is that unreasonable given the environment, but I am open to suggestions.

One way to fix this would be to specify multiple directories for "outDir" instead of restricting it to just one. In doing so, vscode-node-debug would be able to search in multiple custom locations for sourcemaps instead of just the main project compilation folder.

Please let me know if you need me to explain this in any more detail.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions