gpt4 book ai didi

typescript - "Cannot launch program ' E :\typescriptBasis\main. ts ' because corresponding JavaScript cannot be found."

转载 作者:搜寻专家 更新时间:2023-10-30 21:13:40 25 4
gpt4 key购买 nike

我正在 Windows 10 中使用 visual studio code 学习 typescript ,但我在运行简单程序时遇到错误。
“无法启动程序‘E:\typescriptBasis\main.ts’,因为找不到相应的 JavaScript。”因此我无法调试代码。

我已经安装了nodejs v10.2.1版本
我已经安装了npm v5.6.0版本
我已经全局安装了 typescript v2.8.3
我已经安装了Visual sudio code v1.23.1

launch.json 文件

  "version": "0.2.0",   
"configurations": [
{
"type": "node",
"request": "launch",
"sourceMaps": true,
"name": "Launch Program",
"program": "${workspaceFolder}/main.ts",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}

tsconfig.json 文件

{  
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}

任务.json

{   
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": ".vscode\\tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
]
},
{
"type": "typescript",
"tsconfig": ".vscode\\tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

main.ts 文件

console.log("这是我的第一个 typescript 程序");

最佳答案

我让它和下面的一起工作launch.json:

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"preLaunchTask": "TSC",
"program": "${file}",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}

tsconfig.json:

{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"allowJs": false,
"sourceMap": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"esModuleInterop": true
}
}

tasks.json:

{
"version": "2.0.0",
"tasks": [
{
"label": "TSC",
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
]
}
]
}

我当前的 VS Code 版本是 1.28.2

关于typescript - "Cannot launch program ' E :\typescriptBasis\main. ts ' because corresponding JavaScript cannot be found.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com