如何在Visual Studio Code中调试TypeScript Express应用

时间:2018-11-16 10:29:19

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

我试图在Visual Studio Code中调试TypeScript Express应用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'

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

1 个答案:

答案 0 :(得分:-1)

node-notification-service使用tsconfig-paths来获得运行时模块解析度,以兑现paths中定义的tsconfig.json,如您在package.json中所见:

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

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

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