问题描述
我使用的是Visual Studio Code 1.17,我的目标是调试当前的打字稿文件。我有一个构建任务正在运行,所以我总是有一个相应的javascript文件,如下所示:
I am using Visual Studio Code version 1.17, and my objective is to debug the current typescript file. I have a build task running, so I always have a corresponding javascript file like this:
src/folder1/folder2/main.ts
src/folder1/folder2/main.js
我试过以下发布.json配置:
I have tried with the following launch.json configuration:
{
"type": "node",
"request": "launch",
"name": "Current File",
"program": "${file}",
"console": "integratedTerminal",
"outFiles": [
"${workspaceFolder}/${fileDirname}**/*.js"
]
}
但我收到错误:无法启动程序'--full-path-to-project - / src / folder1 / folder2 / main.ts'因为无法找到相应的JavaScript。
但相应的JavaScript文件存在!
But the corresponding JavaScript file exists!
tsconfig.json:
tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
"target": "es6",
"lib": [
"es2017",
"dom"
],
"module": "commonjs",
"watch": true,
"moduleResolution": "node",
"sourceMap": true
// "types": []
},
"include": [
"src",
"test"
],
"exclude": [
"node_modules",
"typings"
]}
推荐答案
outFiles
的配置指向错误的目录。
The configuration for your outFiles
points to the wrong directory.
用此替换你的 launch.json
配置将解决它:
Replacing your launch.json
config with this would fix it:
{
"type": "node",
"request": "launch",
"name": "Current File",
"program": "${file}",
"console": "integratedTerminal",
"outFiles": ["${fileDirname}/*.js"]
}
来自:
应该是您需要的目录。
should be the directory you need.
请注意,您也可以使用outFiles:[$ {fileDirname} / ** / * .js]
包含子目录。
Note that you can also use "outFiles": ["${fileDirname}/**/*.js"]
to include subdirectories.
您正在使用的配置添加以下目录:
The configuration you're using adds the following directory:
"${workspaceFolder}/${fileDirname}**/*.js"
其转换为:
"/path/to/root/path/to/root/src/folder1/folder2/**/*.js"
ie根目录的路径在那里两次,使其成为无效路径。
i.e. the path to the root is in there twice, making it an invalid path.
如果您的.js文件位于不同的 outDir
:只需使用此目录的路径即可。打字稿 sourceMaps
将完成剩下的工作。
If your .js files are on a different outDir
: simply use the path to such directory. Typescript sourceMaps
will do the rest.
例如,如果你把 .js
dist
目录中的文件:
For example, if you put your .js
files in a dist
directory:
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
这篇关于无法在VS Code中调试当前的typescript文件,因为找不到相应的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!