Ignacio Ribas
Ignacio Ribas

Reputation: 11

Angular 19: Error when hot-reloading after file change

I've recently updated Angular to version 19 and get the following error after I edit and save a file while the development server is running:

An unhandled exception occurred: 
Failed to load url /main.server.mjs (resolved id: /main.server.mjs). Does the file exist?
See "/private/tmp/ng-UXJ60K/angular-errors.log" for further details.
/Users/xyz/Documents/.../git/my_project/node_modules/rxjs/dist/cjs/internal/util/reportUnhandledError.js:13
            throw err;
            ^

Error: Failed to load url /main.server.mjs (resolved id: /main.server.mjs). Does the file exist?
    at loadAndTransform (file:///Users/xyz/Documents/.../git/my_project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:51787:17)
    at async instantiateModule (file:///Users/xyz/Documents/.../git/my_project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:52746:44) {
  code: 'ERR_LOAD_URL'
}

Something to notice is that, during the migration to Angular 19, the builder that's used for development is no longer @angular-devkit/build-angular (^18.1.1) but @angular/build (19.0.6).

Actually, if I do reinstall angular-devkit/build-angular@18 and ignore the legacy-peer-deps (which I'm trying to avoid), hot-reloads don't cause the aboved mentioned issue anymore. Still, this is a dirty workaround and doesn't solve the underlying problem, especially when considering that with the new angular-devkit/build-angular@19 .

As this seems to be a vite problem, I've also tried to install it in my project (aka add it as a dependency in package.json) and even tried changing the peer dependency version for @angular/build -> vite from 5.4.11 to 5.4.6, which previously had no issues with angular-devkit/build-angular. I still got the same error.

A clean install (including deleting .angular and node_modules) doesn't work either.

This seems to be new with the Angular 19 release, and I've seen some of these dependencies have been getting updates recently. I just wanted to know if anyone got that same issue. Thx!

Upvotes: 1

Views: 854

Answers (0)

Related Questions