WebStorm Node.js TypeScript Express调试卡在连接到本地主机上

WebStorm Node.js TypeScript Express debug stuck on connecting to localhost

我正在尝试使用WebStorm调试TypeScript Express应用程序。

我在package.json中有此调试脚本

1
2
3
4
"scripts": {
    ...
   "debug":"node --inspect-brk=9229 --require ts-node/register -r tsconfig-paths/register server.ts"
}

我在命令行中运行npm run debug并加载以下内容

1
2
Debugger listening on ws://127.0.0.1:9229/<somerandomid>
For help see https://nodejs.org/en/docs/inspector

现在,我可以通过进入Chrome浏览器从Chrome检查器进行调试,键入chrome://inspect/,并且server.ts将出现在Remote Target中,并且可以通过单击inspect调试TypeScript。因此,我知道问题不在于我的node.js配置方面。

问题是,使用WebStorm时无法调试。

我尝试了以下WebStorm调试配置:

1
2
3
4
Attach to Node.js/Chrome
Host: localhost
Port: 9229
Attach to: Chrome or Node.js > 6.3 started with --inspect

但是当我在WebStorm中进行调试时,调试器会继续说"Connecting to localhost:9229",但什么也没有发生。即使我在server.ts等中设置了断点,它也不会到达断点

我尝试禁用防火墙,但仍然无法正常工作。使用--inspect而不是--inspect-brk尝试,仍然不起作用。

我在做什么错,如何使用我的node.js Express TypeScript配置让WebStorm调试到断点?


使用您的方式启动应用程序/附加调试器,对我来说效果很好。 您使用什么WebStorm版本?
这是另外两种调试应用的方法:

  • 使用Node.js运行配置(创建类似的配置并按Debug):

enter image description here

  • 使用NPM运行配置:

  • 将脚本更改为"debug":"node %NODE_DEBUG_OPTION% --require ts-node/register -r tsconfig-paths/register server.ts"(如果在Linux / Mac OSX上,请将%NODE_DEBUG_OPTION%替换为$NODE_DEBUG_OPTION

  • 单击装订线中的箭头,选择"调试"

enter image description here