48

I suddenly can't debug my Angular Application. Not quite sure what I did. It might have happen after I updated node.js

  • Angular: 13.1.1
  • NodeJS: 18.1.0
  • VSCode: 1.67.1

Launch.json

"configurations": [
    {
      "type": "pwa-chrome",
      "request": "launch",
      "name": "Launch Chrome against localhost",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}/src",
      "sourceMaps": true,
    },
  ]

Errors:

Could not read source map for http://localhost:4200/runtime.js: Unexpected 503 response from http://127.0.0.1:4200/runtime.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/vendor.js: Unexpected 503 response from http://127.0.0.1:4200/vendor.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/main.js: Unexpected 503 response from http://127.0.0.1:4200/main.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/styles.js: Unexpected 503 response from http://127.0.0.1:4200/styles.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/polyfills.js: Unexpected 503 response from http://127.0.0.1:4200/polyfills.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/scripts.js: Unexpected 503 response from http://127.0.0.1:4200/scripts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/common.js: Unexpected 503 response from http://127.0.0.1:4200/common.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/common.js: Unexpected 503 response from http://127.0.0.1:4200/common.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_lora_lora_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_lora_lora_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_telegrams_telegrams_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_telegrams_telegrams_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_items-management_items-management_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_items-management_items-management_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_model-management_model-management_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_model-management_model-management_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_key-management_key-management_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_key-management_key-management_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/default-src_app_model-management_services_items_service_ts-src_app_model-management_services_-687318.js: Unexpected 503 response from http://127.0.0.1:4200/default-src_app_model-management_services_items_service_ts-src_app_model-management_services_-687318.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_gum_gum_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_gum_gum_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/src_app_biot_biot_module_ts.js: Unexpected 503 response from http://127.0.0.1:4200/src_app_biot_biot_module_ts.js.map: connect ECONNREFUSED 127.0.0.1:4200
1
  • first move is conforming to the version guide angular.io/guide/versions before trying anything else Commented Sep 11, 2023 at 13:48

13 Answers 13

67

I actually had the same problem (using Angular 14 with NX). The debugger would work on node 16 but not on node 18.

What made it work is adding the flag '--host=127.0.0.1' to the start script in package.json.

"start": "ng serve --host=127.0.0.1"

My launch json:

 "version": "0.2.0",
  "configurations": [
    
    {
      "name": "Debug Frontend",
      "type": "pwa-chrome",
      "request": "launch",
      "preLaunchTask": "Serve Frontend",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:/*": "${webRoot}/*",
        "/./*": "${webRoot}/*",
        "/src/*": "${webRoot}/src/*",
        "/*": "*",
        "/./~/*": "${workspaceFolder}/node_modules/*"
      }
    }

My tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Serve Frontend",
      "type": "npm",
      "script": "start",
      "isBackground": true,
      "presentation": {
        "focus": true,
        "panel": "dedicated"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": {
        "owner": "typescript",
        "source": "ts",
        "applyTo": "closedDocuments",
        "fileLocation": ["relative", "${cwd}"],
        "pattern": "$tsc",
        "background": {
          "activeOnStart": true,
          "beginsPattern": {
            "regexp": "(.*?)"
          },
          "endsPattern": {
            "regexp": "Compiled |Failed to compile."
          }
        }
      }
    }
  ]
}

Edit: If you are using NX, you need to change the name of your script in tasks.json to match your package.json, as well as need to add the host to the start script in package.json:

"start:frontend": "nx serve frontend --host=127.0.0.1"
Sign up to request clarification or add additional context in comments.

14 Comments

I downgraded to node 16 LTS, works fine now
Adding --host=127.0.0.1 as suggested worked, and I want to know why!
I have struggled with this problem for months and couldn't find a solution, this finally solved it - thank you! I'm with calebTree8475 though, I'd really like to know what changed between the Node versions that broke this...
It works with node v18.12 thanks! But with your launch json and your tasks.json you need to add in package.json this line: "start:frontend": "ng serve --host=127.0.0.1"
Exactly, this is a life saver.
|
22

I've found a simpler solution here.

With VSCode 1.74.0, Angular 14 and NodeJS 18 I simply added the resolveSourceMapLocations property to my launch.json:

{
   "name": "Chrome debug",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:4200",
    "webRoot": "${workspaceFolder}",
    "preLaunchTask": "starter",
    "sourceMaps": true,
    "resolveSourceMapLocations": [
        "${workspaceFolder}/**",
        "!**/node_modules/**"
    ],
}

No need to update the package.json serve configuration.

4 Comments

adding resolveSourceMapLocations prevents being able to hit breakpoints for me. Not sure about that solution for this issue.
@John had this problem, was solved after removing of "${workspaceFolder}/**"
Works like a charm. This should be the accepted answer. I had no issues with breakpoints, but I'll keep that in mind.
Did not work. With this change breakpoints are not getting set.
12

It appears that in node v18 localhost resolves to an ipv6 address instead of ipv4 in v16. In the browser localhost will resolve to ipv4 and the angular node server errors out.

On v18 you can put an ipv6 address:

"configurations": [
{
  "name": "ng serve",
  "type": "chrome",
  "request": "launch",
  "url": "http://[::1]:4200/"
},

and it should work

https://github.com/nodejs/node/issues/40537

1 Comment

This should be the accepted answer because it explains the reason behind this bug and deals directly with it
10

I have recently faced the same problem, which I could manage out by adding the suggested line: "start": "ng serve --host=127.0.0.1"

It worked. However, I had to remember starting ng with the explicit host each time I wanted to debug. I ran "ng version" and suddenly the command complained that Angular did not support Node.js v.18!

I have uninstalled Node.js v.18 and then installed v.16. That has completely fixed the problem.

Comments

6

Cause

The default value of the --dns-result-order flag changed in NodeJS v17 from ipv4first to verbatim. Here's the PR that made the change: dns: default to verbatim=true in dns.lookup() #39987.

This change in behaviour was noticed in this issue ticket: "localhost" favours IPv6 in node v17, used to favour IPv4 #40537. The change is mentioned in the changelog under "Other Notable Changes".

Solution

You have a few options:

  • Check your hosts file. If it's missing ::1 localhost, adding that might solve the issue.

  • Pass --dns-result-order=ipv4first to your node process.

  • Change your VS Code debugging launch config to open the IPv6 loopback address ([::1]) explicitly.

  • Specify the desired host explicitly in the ng serve command (ng serve --host=127.0.0.1).

Comments

5

My system: Ubuntu 22, node 18.11

I figured out, it depends on two things: node version or host ip

I switched to node 16.18, and it worked.

It depends also not on my launch.json config. "sourceMaps" is not needed:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "attach",
      "name": "Attach to browser",
      "port": 9222
    }
  ]
}

Another fix (using node 18) is modify package.json:

"start": "ng serve --host=127.0.0.1",

Instead of:

"start": "ng serve",

2 Comments

finally someone told where "start": "ng serve --host=127.0.0.1", placed in! all said change ("start": "ng serve") to ("start": "ng serve --host=127.0.0.1").BUT not said where it is. lunch.js OR package.js OR WHERE????? only one was you.thanks
You saved me, I was already worrying.
2

I have been working in parallel these last years in Angular projects created from version 7 to the most current and there is something that I have learned.

The version we use of Angular and Nodejs must be aligned.

Check out this helpful answer about compatibility between Angular CLI, Angular, Node.js, TypeScript and RxJS version compatibilities.

Comments

2

You can follow this open issue's thread if you are using VSCode. Now, this issue is still lingering because of a bug in the DNS resolution fallback logic in VSCode.

Forcing the devserver to 127.0.0.1 is the only workaround for now.

The github issue: https://github.com/microsoft/vscode/issues/167353 This issue is phrased as angular related, but it's Webpack's devserver in general.

Comments

1

I downgraded NodeJS to version 14.19.x which fixed the issue for me.

1 Comment

node 18 didn't work for me downgraded to node 16 now it works
1

Changing settings on files didn't work for me, but running the app with the following comand solved the problem:

ng serve --host=127.0.0.1 --open

1 Comment

The --open flag is optional, of course.
1

Try once of both solution!

launch.json

"resolveSourceMapLocations": [
  "${workspaceFolder}/**",
  "!**/node_modules/**"
],

webpack.config.js

output: {
  devtoolModuleFilenameTemplate: (info) => {
    if (process.env.NODE_ENV === 'production') {
      return `webpack:///${info.resourcePath}`;
    } else {
      return 'file:///' + encodeURI(info.absoluteResourcePath);
    }
  },
},

Comments

1

I had to downgrade the vscode version from 1.95 to 1.94. This fixed the issue in my case. It seems to be related with a bug from the vscode side too.

1 Comment

I'm having the same issue after an upgrade to 1.95.2. I can no longer do Launch Chrome (workspace), it hangs and there's the error Could not read source map for runtime.js: NOENT: no such file or directory, open runtime.js.map. It does work against yarn start but not yarn dev. I have a related thread: stackoverflow.com/questions/79189786/…
0

Worth noting is the impact to a CORS proxy.config.json. Updating your VS Code launch.json to IPV6 as below (per pdog and starball):

"configurations": [
{
  "name": "ng serve",
  "type": "chrome",
  "request": "launch",
  "url": "http://[::1]:4200/"},
  ...

will break an existing IPV4 oriented CORS proxy. You will need to add "changeOrigin" to the config if your services run on IPV4.

{
  "/api": {
    "target": "https://localhost:44371",
    "secure": false,
    "pathRewrite": {"^/api": ""},
    "changeOrigin": true
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.