【问题标题】:Why is VSCode launching node, instead of TypeScript?为什么 VSCode 启动节点,而不是 TypeScript?
【发布时间】:2021-09-23 09:33:50
【问题描述】:

我在 VSCode 中有一个要调试的 TypeScript 文件。

当我启动它时,VSCode 会启动“node CheckFMBackup.ts”,而不是先在 CheckFMBackup.ts 上调用 TypeScript,然后再调用“node CheckFMBackup.js”。

为什么VSCode不调用“node CheckFMBackup.js”,而是调用“node CheckFMBackup.ts”?

我是否配置错误?我知道调用节点而不是 TypeScript 的原因在下面的屏幕截图中。我已在已检查和未检查的异常上启用断点。

CheckFMBackup.ts:


    const BITQUERY_API_URL = "";
    const BITQUERY_API_KEY = "";
    const axios = require("axios");
    
    async function makeRequest(query: string) {
        const result = await axios.post(BITQUERY_API_URL, {
            query: query,
            headers: {
                "Content-Type": "application/json",
                "X-API-KEY": BITQUERY_API_KEY
            }
        });
      
        return result.data;
    }

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\CheckFMBackup.ts",
            "outFiles": [
                "${workspaceFolder}/out/**/*.js"
            ],
            "preLaunchTask": "tsc: build - tsconfig.json", 
        }
    ]
}

tasks.json:

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

tsconfig.json:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    "target": "es2017",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
    "module": "es2020",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "outDir": "./out",                              /* Redirect output structure to the directory. */
    "strict": true,                                 /* Enable all strict type-checking options. */
    "esModuleInterop": true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */
  }
}

【问题讨论】:

    标签: typescript visual-studio-code


    【解决方案1】:

    我认为您可以编辑您的preLaunchTask。您应该为任务命名,例如在您的launch.json

    {
        "configurations": [
            {
                ...
                "preLaunchTask": "tscBuild"
            }
        ]
    {
    

    在你的tasks.json

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "tscBuild",
                "command": "tsc: build - tsconfig.json",
                ...
          
            },
    }
    

    【讨论】:

    • 更改构建任务名称如何使 VSCode 启动节点?
    猜你喜欢
    • 2017-11-24
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 2010-10-28
    • 2015-05-21
    相关资源
    最近更新 更多