gpt4 book ai didi

node.js - 无法使用 babel-node 为 Node 启动 VSCode 调试器

转载 作者:搜寻专家 更新时间:2023-10-31 23:34:29 26 4
gpt4 key购买 nike

当我在控制台中键入 npm run debug 时,我得到:"Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834"。当我在 chrome 中访问这个地址时,我唯一看到的是 "WebSockets request was expected"。我应该调整配置的哪些部分以使调试器工作?我正在使用最新版本的 nodejs。

package.json 脚本

"scripts": {
"prod": "webpack -p --env.production --progress",
"start": "babel-node --presets es2015 server/server.js",
"watch": "nodemon --exec npm run start",
"debug": "babel-node --presets es2015 server/server.js --inspect --debug-brk=3090"
}

启动.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"program": "${workspaceRoot}/server/server.js",
"restart": true,
"runtimeArgs": [
"run-script", "debug"
],
"port": 3090
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3090",
"webRoot": "${workspaceRoot}"
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 3090,
"webRoot": "${workspaceRoot}"
}
]
}

文件结构:

├───.vscode
├───js
├───server
│ ├───db
│ ├───middleware
│ ├───models
│ ├───server.js

enter image description here

最佳答案

这似乎是 nodejs 库版本 >= 7.0.0 的问题。

第一个解决方法:

使用开发工具在 chrome 中打开此文件的一个小解决方法是在您的情况下复制 ws 之后的链接代码:

Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834

并将其附加到带有 ws= 的开发工具链接行的末尾,如下所示:

chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834

这将使您能够在 chrome 开发工具中打开您的程序。给出了问题的链接和解决方案 here

第二种解决方法:

我尝试安装旧版本的 Node ,即 6.11.2 和 npm 3.10,并在 visual studio code 中进行了尝试,它运行良好,没有任何问题。

但是,使用上面第一种方法中显示的技巧,我仍然能够使用最新版本的 Node 和 npm。

编辑:格式化我的答案以便更好地理解

关于node.js - 无法使用 babel-node 为 Node 启动 VSCode 调试器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45470362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com