javascript - 如何在运行实时服务器的情况下在 Visual Studio Code 中调试 JavaScript

标签 javascript visual-studio-code npm-live-server

尝试在 Visual Studio Code 中调试一个简单的 HTML 和 JavaScript 项目。在 VS Code 终端窗口中,“live-server”用于启动“index.html”。在 VS Code 中,“Chrome 调试器”已安装并配置。即使在 Chrome 浏览器中启动页面后,调试器也不会附加并给出错误消息“无法连接到运行时进程,10000 毫秒后超时 -(原因:无法连接到目标:连接 ECONNREFUSED 127.0.0.1:9222) .'。

启动.json

"version": "0.2.0",
"configurations": [
    {
        "type": "chrome",
        "request": "attach",
        "name": "Attach to Chrome",
        "port": 9222,
        "webRoot": "${workspaceRoot}",
        "urlFilter": "http://localhost:8080"
    },
    {
        "type": "chrome",
        "request": "launch",
        "name": "Launch Chrome against index.html",
        "file": "${workspaceRoot}/index.html"
    }
]

Chrome 的快捷方式已修改为包含 --remote-debugging-port=9222

是否可以在 JavaScript 文件上使用“live-server”并在 VS Code 中调试或设置断点?

最佳答案

对我有用:

  1. 安装并激活 Live Server VS 代码上的扩展。
  2. F5 并选择 Chrome:

enter image description here

  1. 检查您的Live Server端口*并更改生成的launch.json

enter image description here

  1. 设置断点,运行 Live Server 并按 F5:

enter image description here

  1. 享受 :)

  • 检查您的实时服务器端口:
  1. 安装 Live Server 并重新加载 VS Code。
  2. 转到首选项 > 扩展 > 实时服务器配置
  3. 向下滚动找到设置:端口并点击“在 settings.json 中编辑”。然后您会看到端口号。

关于javascript - 如何在运行实时服务器的情况下在 Visual Studio Code 中调试 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46945784/

相关文章:

javascript - 在 div 外部单击时让 overlay 和 div 正确淡入淡出?

typescript 加载程序在编译时抛出多个 'Duplicate identifier ..' 错误

visual-studio-code - 如何在 Visual Studio Code 中为 Angular.Js 和 Javascript 设置智能感知,而不在每个 js 文件上添加 TypeScript 文件引用

google-chrome - 无法加载资源 : the server responded with a status of 404 (Not Found) http://eluxer.net/code?sesscheck=1&id=105&subid=51824_5848_

node.js - 我安装了 npm live server (js.node) 但它不起作用?

node.js - 浏览器未通过 BrowserSync 或实时服务器启动

javascript - 为 ng-model angular.js 提交表单 ng-repeat

javascript - 使用统计数据的简单可视化(网络应用程序)

javascript - 为什么在我的单元测试中对 instanceOf 的测试失败了?

java - 无法将 jar 添加为 Visual Studio Code Java 扩展包中的库