简体   繁体   中英

How to debug TypeScript Express app in Visual Studio Code

I tried to debug the TypeScript Express App https://github.com/schul-cloud/node-notification-service/ in Visual Studio Code.

in launch.json I added the configuration

{
        "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"
    }

But when I run the configuration the debugger fails with

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

How do I start the debugger correctly so that it finds the modules?

node-notification-service is using tsconfig-paths to get runtime module resolution to honor the paths defined in tsconfig.json , as you can see in package.json :

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

So you'll need to add tsconfig-paths to your launch configuration, like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM