我刚刚创建了一个新项目并第一次使用 F5 或 ctrl + f5 运行它,Chrome 中的结果是“无法访问该站点”
“err_connection_refused”
我尝试从终端“ng s -o”运行并且一切正常,该站点在端口 4200 上运行良好,
但我喜欢调试。
这是我的 launch.json 文件,全部默认
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
小智 87
我也遇到了这个问题,列出的解决方案都没有帮助。不过,问题倒是很容易解决。
只需进入Chrome 开发者控制台的“网络”选项卡即可。确保连接处于No throtting且不是Offline 状态。
Mik*_*ise 65
这个误导性的错误消息似乎与 Chrome 或任何已弃用的功能无关。它可能有很多根本原因,并且似乎在无法建立连接时就会发生。
我是在关注 Visual Studio Code 的 React 教程时得到的。在该教程中,您首先使用 创建模板,npx然后使用 运行它npm start。这很有效,我可以看到它在浏览器中使用http://localhost:3000作为 URL。
然而,当我按照教程的要求更改代码并设置断点进行调试时,我在 OP 的帖子中收到了错误,无论是使用 Chrome 还是使用 Edge。
Visual Studio Code 正在创建一个默认的launch.json文件用于调试并填充它,如下所示:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要手动将 8080 更改为 3000 这解决了问题。
对我来说,关键是配置断点以捕获异常,如所描述的 OP(注意 - 您只能使用最左侧图标菜单中选择的“调试”图标进行配置)。虽然发出的错误消息仍然是误导性的“已弃用”消息,但有一条消息“无法访问该站点”,如果您稍微挖掘一下,您就可以找到该消息 - 如下所示:
我想几乎任何导致连接失败的配置问题都会导致此错误。所以防火墙问题,缺少主机程序,错误的配置(比如我的)等等。
小智 7
我遇到了同样的问题,问题出在 url 上,它https://localhost:8000;代替了http://localhost:8000. 因此,请尝试检查您的网址和路线。
小智 5
尝试这个:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Chrome against localhost",
"type": "dart"
}
]
}
Run Code Online (Sandbox Code Playgroud)
小智 2
我有类似的问题。然而,我发现了一个不同的解决方案。仍然值得检查 OP\xe2\x80\x99s 解决方案的 GitHub 链接中的步骤。
\n我正在处理的项目是在旧版本中制作的,并且launch.json URL 有 // 分隔符。将它们替换为无分隔符解决了该问题。
\n从
\n"url":"file:///C://exampleParent//exampleChild//file.txt"\nRun Code Online (Sandbox Code Playgroud)\n到
\n "url":"file:///c:/exampleParent/exampleChild/file.txt"\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
128049 次 |
| 最近记录: |