我试图在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'
如何正确启动调试器,以便找到模块?
答案 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"],