angularbuildmigration

Resource not found on ng serve after update to new Angular 18 build system


After the update to Angular 18, including the automatic migration to the new build system, it got a terrible Resource not found when accessing http://localhost:4200/ after launching npm start linked to the command ng serve --proxy-config proxy.conf.json as described in my package.json.


Solution

  • I discovered it came from the proxy.conf.json file which was working fine with the old build system from Angular:

    {
      "/": {
        "target": "http://localhost:1234/",
        "secure": false,
        "changeOrigin": true
      }
    }
    

    And to correct the issue, you have to be more specific when giving the redirected path to your REST endpoints:

    {
      "/service": {
        "target": "http://localhost:1234/",
        "secure": false,
        "changeOrigin": true
      }
    }