Sta*_*ers 2 javascript debugging node.js docker visual-studio-code
我正在尝试将 macOS Catalina 上的 Visual Studio Code 中的调试器用于节点应用程序。我创建了一个非常简单的例子来说明我的情况。
索引.js
require('http').createServer( (request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Hello World\n');
response.end();
}).listen(3000);
Run Code Online (Sandbox Code Playgroud)
文件
FROM node:12.14.0-alpine
COPY . /src
CMD ["node","--inspect=0.0.0.0", "src/index.js"]
Run Code Online (Sandbox Code Playgroud)
我构建了 Dockerfile
docker build . -t debugtest
Run Code Online (Sandbox Code Playgroud)
然后运行它
docker run -p 3000:3000 -p 9229:9229 debugtest
Run Code Online (Sandbox Code Playgroud)
我可以访问http://localhost:3000/。
我在 index.js 中设置了一个断点。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"skipFiles": [
"<node_internals>/**"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,当我以可视化代码启动调试器时,断点的红点消失,并出现“断点设置但尚未绑定”。
我在各个地方都看到过这个问题,但没有一个解决方案有效。当我在 docker 之外运行节点进程时,node --inspect index.js它可以顺利运行。
我使用的是 1.41.1 版的 Visual Studio 代码和 docker 2.1.0.5。
原来我省略remoteRoot的属性launch.json。下面的作品。
启动文件
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"remoteRoot": "/src/",
"skipFiles": [
"<node_internals>/**"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
848 次 |
| 最近记录: |