【问题标题】:Unbound breakpoint in vscode for debugging nodejs app in a docker containervscode 中的未绑定断点,用于在 docker 容器中调试 nodejs 应用程序
【发布时间】:2021-01-22 21:47:15
【问题描述】:

最小的可重现回购: https://github.com/ShocKwav3/babel-node-basic

我正在尝试使用 vscode 为 nodejs 应用程序设置调试器。我正在使用babel-node 运行该应用程序。无论我尝试什么,断点都显示为未绑定。 我正在使用此命令运行应用程序

nodemon --exec './node_modules/.bin/babel-node --inspect=0.0.0.0 src/bin/www'

Dockerfile:

FROM node:12
WORKDIR /usr/src/app/home_automation_server
COPY package*.json ./
RUN yarn install
COPY . .

编写配置:

server:
    image: home_automation_server
    volumes:
      - .:/usr/src/app/home_automation_server
    working_dir: /usr/src/app/home_automation_server
    ports:
      - 3000:3000
      - 9229:9229
    depends_on:
      - db
      - redis
    networks:
      - servernet
    env_file:
      - ./server.env
      - ./database.env
    command: ["sh", "entrypoint.sh", "run"]
    tty: true

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",{
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    ["module-resolver", {
      "root": ["./"],
      "alias": {
        "projectRoot": "./",
        "src": "./src"
      }
    }]
  ],
  "sourceMaps": "inline"
}

launch.json:

{
      "type": "node",
      "request": "attach",
      "name": "Debug: HA dev server",
      "port": 9229,
      "restart": true,
      "trace": true,
      "address": "localhost",
      "localRoot": "${workspaceFolder}/src/bin",
      "remoteRoot": "/usr/src/app/home_automation_server/src/bin",
      "protocol": "inspector",
      "sourceMaps": true
    }

当我连接调试器时,它会连接 如果我使用inspect-brk,应用程序会在第一行停止,当调试器连接时,我可以单步执行。 但是当我设置断点时它不起作用并且变灰。说“未绑定断点” 我究竟做错了什么?我已经在这方面工作了很长时间,并且几乎尝试了通过 google 搜索可以找到的所有内容。

【问题讨论】:

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


【解决方案1】:

欣赏它不完全相同的问题。我在使用 VSCode 的 Angular 中遇到了未绑定断点的问题。 this github issue 中有一些信息可能有用。

注意,您可以在suggestions in this comment (part of the same github issue) 之后从 VSCode 收集调试跟踪

【讨论】:

  • 我也检查过这个,不幸的是没有帮助我的情况:(
【解决方案2】:

我遇到了类似的问题,问题出在 launch.json,我在属性中遇到了 "program": "app.ts",我改成了"program": "$ {file}"**。我只能测试app.ts。在其他文件中,断点设置为“未绑定” 这是我的launch.json

    {

    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}",
            "sourceMaps": true,
            "preLaunchTask": "tsc: build - tsconfig.json",
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
    ]
}

【讨论】:

    猜你喜欢
    • 2017-12-18
    • 2021-11-21
    • 2020-10-04
    • 1970-01-01
    • 2022-06-29
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多