如何在 WebStorm 的调试模式下使用 TypeScript 运行 Nodemon
How to run Nodemon with TypeScript in debug mode in WebStorm
我有一个非常基本的 Express 服务器设置 NodeJS/Express + Nodemon。我正在使用 WebStorm 作为我的 IDE.
当 运行 运行 debug/inspect 脚本时,我的应用程序抛出一个编译时错误。按照说明 here, and cognizant of the post here,我的(简化的)package.json
看起来像这样:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/app.ts",
"debug": "nodemon --inspect=127.0.0.1:9229 src/app.ts"
},
"devDependencies": {
"@types/express": "^4.17.9",
"@types/node": "^14.14.19",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
}
当我 运行 npm run debug
我收到以下错误:
我也试过以下方法,结果都一样:
"debug": "nodemon --inspect src/app.ts"
"debug": "nodemon --inspect=0.0.0.0:9229 src/app.ts"
知道为什么会出现此错误吗?
命令npm run dev
没有产生错误。经过进一步调查,nodemon 在针对 .ts
文件时自动替换 ts-node。 ts-node,反过来,recommends 通过注册 ts-node 进行调试,运行使用 node 命令连接服务器。
If you need to use advanced node.js CLI arguments (e.g. --inspect),
use them with node -r ts-node/register
instead of the ts-node CLI.
您可以按如下方式修改您的脚本:
"debug": "nodemon --exec \"node --inspect-brk=0.0.0.0:9229 --require ts-node/register src/app.ts\""
确保 --inspect-brk
传递给 Node.js 而不是 ts-node
我有一个非常基本的 Express 服务器设置 NodeJS/Express + Nodemon。我正在使用 WebStorm 作为我的 IDE.
当 运行 运行 debug/inspect 脚本时,我的应用程序抛出一个编译时错误。按照说明 here, and cognizant of the post here,我的(简化的)package.json
看起来像这样:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/app.ts",
"debug": "nodemon --inspect=127.0.0.1:9229 src/app.ts"
},
"devDependencies": {
"@types/express": "^4.17.9",
"@types/node": "^14.14.19",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
}
当我 运行 npm run debug
我收到以下错误:
我也试过以下方法,结果都一样:
"debug": "nodemon --inspect src/app.ts"
"debug": "nodemon --inspect=0.0.0.0:9229 src/app.ts"
知道为什么会出现此错误吗?
命令npm run dev
没有产生错误。经过进一步调查,nodemon 在针对 .ts
文件时自动替换 ts-node。 ts-node,反过来,recommends 通过注册 ts-node 进行调试,运行使用 node 命令连接服务器。
If you need to use advanced node.js CLI arguments (e.g. --inspect), use them with
node -r ts-node/register
instead of the ts-node CLI.
您可以按如下方式修改您的脚本:
"debug": "nodemon --exec \"node --inspect-brk=0.0.0.0:9229 --require ts-node/register src/app.ts\""
确保 --inspect-brk
传递给 Node.js 而不是 ts-node