【问题标题】:Breakpoint set but not yet bound in Visual Studio Code for a dockerized node process已在 Visual Studio Code 中为 dockerized 节点进程设置但尚未绑定的断点
【发布时间】:2020-05-09 04:29:12
【问题描述】:

我正在尝试将 macOS Catalina 上的 Visual Studio Code 中的调试器用于节点应用程序。我创建了一个非常简单的示例来说明我的情况。

index.js

require('http').createServer( (request, response) => {
  response.writeHead(200, {'Content-Type': 'text/plain'})
  response.end('Hello World\n');
  response.end();
}).listen(3000);

Dockerfile

FROM node:12.14.0-alpine 
COPY . /src
CMD ["node","--inspect=0.0.0.0", "src/index.js"]

我构建了 Dockerfile

docker build . -t debugtest

然后运行它

 docker run -p 3000:3000 -p 9229:9229 debugtest

我可以访问http://localhost:3000/

我在 index.js 中设置了一个断点。

然后在 Visual Studio 代码中设置一个调试器目标

{
  "version": "0.2.0",
  "configurations": [
  {
    "type": "node",
    "request": "attach",
    "name": "Attach",
    "port": 9229,
    "skipFiles": [
      "<node_internals>/**"
    ]
  }
  ]
}

现在,当我在可视代码中启动调试器时,断点的红点会消失,并出现“已设置断点但尚未绑定”。

我在各个地方都看到过这个问题,但没有一个解决方案奏效。当我在 docker node --inspect index.js 之外运行节点进程时,它可以顺利运行。

我正在使用 1.41.1 版的 Visual Studio 代码和 docker 2.1.0.5。

【问题讨论】:

    标签: javascript node.js docker debugging visual-studio-code


    【解决方案1】:

    原来我在launch.json 中省略了remoteRoot 属性。下面的作品。

    launch.json

    {
      "version": "0.2.0",
      "configurations": [
      {
        "type": "node",
        "request": "attach",
        "name": "Attach",        
        "port": 9229,
        "remoteRoot": "/src/",
        "skipFiles": [
          "<node_internals>/**"
        ]
      }
      ]
    }
    

    【讨论】:

    • 这救了我的命!我使用了“默认”launch.json,这是在您选择“附加到 Docker”时创建的。它有一个remoteRoot 属性,但它指向/usr/src/app,这不是我将应用程序代码放入容器中的位置,因此只需将其更改为我的代码在容器中的位置即可解决此问题。
    • 也救了我,所以我也不知道remoteRoot 是我从Dockerfile 获得的容器内应用程序代码的路径
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2019-07-18
    • 1970-01-01
    • 2020-05-18
    • 2018-11-12
    • 1970-01-01
    相关资源
    最近更新 更多