简体   繁体   中英

How to debug Node TypeScript in Visual Studio Code when the JavaScript source is in a different folder

From Visual Studio Code, I am able to debug and step through the TypeScript source of Main.ts, provided the JavaScript and map files coexist in the same folder as the TypeScript source.

This arrangement works -

debugDemo\
     .vscode
              launch.json        
     TypeScript\
               Main.ts
               Main.js
               Main.js.map

However, I don't want the JavaScript files in the TypeScript folder, but instead would like the JavaScript in the JavaScript folder. I understand this can be achieved via a launch.json configuration using the outFiles attribute to identify where to locate the JavaScript.

For me, this arrangement does not work -

debugDemo\
     .vscode
              launch.json        
     TypeScript\
               Main.ts
    JavaScript\        
               Main.js
               Main.js.map

The error is always - "Cannot launch program 'c:\\debugDemo\\TypeScript\\Main.ts'; setting the 'outFiles' attribute might help"

在此处输入图片说明 What is wrong, how can I configure Visual Studio Code to look for the JavaScript files in the JavaScript folder? I experimented with various glob patterns for outFiles , but it did not help resolve the issue.

Main.ts Reduced to one line of code to reduce the problem complexity

  console.log("debug"); 

Mapfiles built via

tsc --sourcemap TypeScript/Main.ts

which generates - TypeScript\\Main.js , TypeScript\\Main.js.map

launch.json

   {
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug Test",
            "program": "${workspaceRoot}/TypeScript/Main.ts",
            "cwd": "${workspaceRoot}",
            "outFiles": ["${workspaceRoot}/JavaScript/**/*.js"],
            "sourceMaps": true
        }
    ]
}
  • TypeScript version: 2.1.4
  • Node version: 6.9.4
  • Visual Studio Code version: 1.14.2

Your command tsc --sourcemap TypeScript/Main.ts does not output the files into JavaScript folder. You have to specify the outDir and specify the JavaScript folder:

tsc --sourcemap --outDir "JavaScript"  TypeScript/Main.ts

See TypeScript compiler options .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM