You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下VSCode运行TypeScript报错:找不到对应JavaScript文件

Fix: "Cannot launch program... because corresponding JavaScript cannot be found" in VS Code TypeScript Debugging

Let's walk through resolving this error step by step. The core issue here is that TypeScript isn't compiling to JavaScript properly, or your VS Code configurations aren't pointing to the right paths for the compiled files.

1. Fix Your tsconfig.json Location & Configuration

First, your tsconfig.json should live in your project root directory (E:\typescriptBasis), not inside the .vscode folder. This ensures the TypeScript compiler automatically picks it up. Let's update it to specify an output directory for compiled JS files (cleaner and easier to reference):

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./dist" // Compiles JS to a /dist folder
  },
  "include": ["**/*.ts"] // Ensures all .ts files in your project are compiled
}

2. Correct tasks.json Paths

Your tasks are pointing to a tsconfig.json inside .vscode, which we just moved. Update the paths to reference the root directory config, and add clear labels for clarity:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "typescript",
      "tsconfig": "./tsconfig.json",
      "option": "watch",
      "problemMatcher": ["$tsc-watch"],
      "label": "tsc: watch" // Auto-recompiles when you edit .ts files
    },
    {
      "type": "typescript",
      "tsconfig": "./tsconfig.json",
      "problemMatcher": ["$tsc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "label": "tsc: build" // One-time compilation for debugging
    }
  ]
}

We need to make sure the debugger knows where to find the compiled JS, and we'll add a pre-launch task to auto-compile before debugging:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "sourceMaps": true,
      "name": "Launch Program",
      "program": "${workspaceFolder}/main.ts",
      "outFiles": ["${workspaceFolder}/dist/**/*.js"], // Points to our /dist output folder
      "preLaunchTask": "tsc: build" // Runs compilation automatically before debugging
    }
  ]
}

4. Verify Compilation Works Manually

Before debugging, open the VS Code terminal and run:

tsc

Check if a dist folder appears with main.js and main.js.map inside. If not:

  • Run tsc -v to confirm your global TypeScript installation (v2.8.3) is working.
  • Double-check that main.ts is in your project root (E:\typescriptBasis) so the include rule in tsconfig.json picks it up.

5. Test Debugging

Now press F5 to start debugging. The pre-launch task will compile your TypeScript first, and the debugger should find the corresponding JS file in the dist folder. You'll see your console log output in the debug terminal.

内容的提问来源于stack exchange,提问作者Anil Avhad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:18:00