title: VS Code "localhost refused to connect" error when starting up launch.json on Mac
body: <p>I have searched and searched and searched for days. I am at my wits end so please be patient with me. I am very new at this.</p>
  <p>I have tried almost all suggestions on the net, to no avail.</p>
  <p>When I try to launch launch.json in VS Code it goes straight to &quot;localhost refused to connect&quot; page. When I launch it via command line using &quot;npm start&quot;, it is successful and no issues are found.</p>
  <p>This is my launch.json file:</p>
  <pre><code>{
      &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          {
              &quot;type&quot;: &quot;chrome&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;timeout&quot;: &quot;10000&quot;,
              &quot;name&quot;: &quot;Launch Chrome against localhost&quot;,
               &quot;url&quot;: &quot;http://localhost:8080&quot;,
              &quot;webRoot&quot;: &quot;${workspaceFolder}&quot;
          }
      ]
  }`
  </code></pre>
  <p>When I try to add the following line to the configurations in launch.json:</p>
  <p><code>&quot;preLaunchTask&quot;: &quot;npm: start&quot;</code></p>
  <p>It somewhat works. The page displays the content on localhost, but the debugger continues to load indefinitely, leaving me unable to press the green arrow to do it again. I have to go to the terminal in VS Code and &quot;control + c&quot; to shut it down but in doing so VS Code launches another localhost that refused to connect, at which point I can press run again to another successful page that seemed to have completely loaded.</p>
  <p>At the same time it displays &quot;localhost refused to connect&quot; this displays in the debug console: &quot;crbug/1173575, non-JS module files deprecated. ...mewebdata/(index)꞉6567:22:6792&quot;. This occurs when I remove the
  <code>&quot;preLaunchTask&quot;: &quot;npm: start&quot;</code>
  from the launch.json file.</p>
  <p>I have tried installing Live Server and running on localhost:5500 but it only gives me a directory of my files and not the actual content itself. I tried creating a tasks.json and a settings.json file. Nada. I've tried the ipconfig /flushdns equivalent on Mac. Nope.</p>
  <p>I would rather not do it any of these ways. I want to press the run button and have Chrome open a localhost of my code successfully. That's all. What is missing here?</p>
  <p>EDIT: I keep getting the error &quot;Chrome didn't shut down properly&quot; every time I run with the offer of restoring my page. I click the X in the top left corner to exit. Is that not what I'm supposed to do?</p>