【问题标题】:How to debug TypeScript Express app in Visual Studio Code如何在 Visual Studio Code 中调试 TypeScript Express 应用程序
【发布时间】:2019-04-19 12:43:54
【问题描述】:

我尝试在 Visual Studio Code 中调试 TypeScript Express App https://github.com/schul-cloud/node-notification-service/

在launch.json中我添加了配置

{
        "name": "notification service launch",
        "type": "node",
        "request": "launch",
        "args": ["src/app.ts"],
        "runtimeArgs": ["-r", "ts-node/register"],
        "outFiles": [ "${workspaceRoot}/build/**/*.js",  "${workspaceRoot}/node_modules/**/*.js" ],
        "cwd": "${workspaceRoot}",
        "protocol": "inspector",
        "internalConsoleOptions": "openOnSessionStart"
    }

但是当我运行配置时,调试器失败了

Error: Cannot find module '@/routes/mail'

如何正确启动调试器以便它找到模块?

【问题讨论】:

    标签: node.js typescript express visual-studio-code


    【解决方案1】:

    node-notification-service 正在使用tsconfig-paths 来获取运行时模块解析,以遵守tsconfig.json 中定义的paths,正如您在package.json 中看到的那样:

      "scripts": {
        // ...
        "server": "ts-node -r tsconfig-paths/register src/app.ts",
        // ...
      },
    

    因此,您需要将tsconfig-paths 添加到您的启动配置中,如下所示:

    "runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
    

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 2016-04-01
      • 2022-07-22
      • 2016-10-12
      • 2018-05-19
      • 2016-12-29
      • 2022-06-15
      • 1970-01-01
      • 2017-04-12
      相关资源
      最近更新 更多