node.js - 如何调试托管在heroku上的远程节点+ babel应用程序?
问题描述
我正在使用托管在 heroku 上的节点运行节点应用程序,并且我已经尝试打开和关闭数周,以使远程调试正常工作。我觉得我已经查看了所有在线资源,并且尝试了所有方法,但我根本无法让它发挥作用。
这是我正在做的事情:
- 部署到 Heroku 没有
Procfile
应该从我的 package.json 运行“start”命令。package.json 看起来像这样
{
"version": "1.0.0",
"main": "src/app.js",
"scripts": {
"build-babel": "babel src -d dist -s --copy-files",
"build": "npm run build-babel",
"start": "npm run build && NODE_ENV=production node --inspect ./dist/app.js",
"heroku-postbuild": "npm install",
},
"dependencies": {
...
},
"devDependencies": {
...
},
"engines": {
"node": "14.12.0"
}
}
一切都按原样开始。然后我运行heroku ps:forward 9229 -a [app-name]
,它输出这个
Establishing credentials... done
SOCKSv5 proxy server started on port 1080
Listening on 9229 and forwarding to web.1:9229
Use CTRL+C to stop port fowarding
现在,当我查看调试器时,它会不断输出Debugger attached
:
2021-11-16T12:33:19.417321+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:21.444303+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:21.446668+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:23.445978+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:23.452337+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:23.452377+00:00 app[web.1]: Debugger listening on ws://127.0.0.1:9229/UUID
2021-11-16T12:33:23.452378+00:00 app[web.1]: For help, see: https://nodejs.org/en/docs/inspector
2021-11-16T12:33:25.423191+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:25.438675+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:25.438703+00:00 app[web.1]: Debugger listening on ws://127.0.0.1:9229/UUID
2021-11-16T12:33:25.438703+00:00 app[web.1]: For help, see: https://nodejs.org/en/docs/inspector
2021-11-16T12:33:27.394681+00:00 app[web.1]: Debugger attached.
2021-11-16T12:33:27.422852+00:00 app[web.1]: Debugger attached.
然后我从 vscode 尝试运行以下启动配置之一:
{
"type": "node",
"request": "attach",
"name": "Heroku",
"address": "localhost",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
},
{
"address": "localhost",
"localRoot": "${workspaceFolder}",
"name": "Attach to Remote",
"port": 9229,
"remoteRoot": "/app",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
他们都附上了我在这里看到的:
但是所有端点都是未绑定的
如果我尝试在由 babel 构建的 dist 文件夹中设置断点,所有断点仍然未绑定。
我尝试过的事情:
- 由于它看起来像调试器正确附加,我认为它可能是源映射。然后我将我的更改
.babelrc
为
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"sourceMap": "inline",
"retainLines": true
}
那没有帮助。
- 将我的启动脚本更改为像这样直接使用 babel 运行,
"start": "npm run build && NODE_ENV=production babel-node --inspect ./dist/app.js",
但断点仍然未绑定。 - 尝试直接通过 chrome 进行调试,它发现了我的节点会话:. 当我检查时,我可以读取远程会话的控制台输出,但是我得到了很多这些错误
DevTools failed to load source map: Could not load content for file:///app/dist/utils/[filename].js.map: System error: net::ERR_FILE_NOT_FOUND
,即使我将项目文件添加到工作区,断点仍然没有被命中。 - 在节点调试文档中,它说我需要 UUID 来调试会话,但我无法在任何地方输入此 UUID。如果我将此添加到地址,它将无法连接。
- 试图转发到另一个端口
heroku ps:forward 9090 -a [app]
,但这无法连接,并且我没有得到显示“已连接调试器”的调试输出 - 可能还有很多其他的事情,但请告诉我,如果您有任何建议,我可以尝试。
解决方案
推荐阅读
- linux - 错误“useradd:组 '100' 不存在”
- jquery - 为什么单击两次后我的事件侦听器与按钮解除绑定?
- c# - 如何使用 C# 处理超大的 .xlsx 文件
- c# - SignalrR HubConnection 忽略查询参数
- c# - 将类添加到 ICollection 列表
- python-3.x - 我们可以使用 Azure DevOps 测试计划进行 Datalake 测试吗
- ios - 如何快速到达附近的加油站并向用户显示方向?
- python - TypeError:after_cancel() 接受 2 个位置参数,但给出了 3 个
- php - vServer 被 Cloudflare 阻止(解决控制台上的验证码)
- python - -215:断言失败