我尝试在 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-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"],
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句