skip to Main Content

I was working on the CSS for my website and accidentally ran it, which opened a JSON file. Now, whenever I try to run any of my HTML files, a new tab is opened that says "unable to connect to local host". I’ve also tried running previous projects and they will not run. I get a message about opening a JSON file instead. Is there a way I can fix this?

I’ve tried reinstalling VS code but that didn’t do anything.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: http
    //go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    
        
        {
            "command": "npm start",
            "name": "Run npm start",
            "request": "launch",
            "type": "node-terminal"
        },
        {
            "name": "Launch Chrome",
            "request": "launch",
            "type": "chrome",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        },
    {
        "name": "Attach to Chrome",
        "port": 9222,
        "request": "attach",
        "type": "chrome",
        "webRoot": "${workspaceFolder}"
    },
    ]
}

2

Answers


  1. To run an HTML file correctly, you just change this JSON section:

    {
        "name": "Launch Chrome",
        "request": "launch",
        "type": "chrome",
        "url": "http://localhost:8080",
        "webRoot": "${workspaceFolder}"
    }
    

    to:

    {
        "name": "Launch Chrome",
        "request": "launch",
        "type": "chrome",
        "file": "${workspaceFolder}/index.html"
    }
    

    Or you can use a local server like XAMPP to run an HTML file as URL http://localhost/index.html

    Login or Signup to reply.
  2. In your config, Launch Chrome‘s port is configured as 8080 but the debugger attaches to port 9222 as configured in Attach to Chrome. Maybe this discrepancy is the problem?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search