Error: Constructor for "ion-app#undefined" was not found after upgrade to Angular 18.1 and Ionic 8

Hi, I have just upgraded my Ionic v7 / Angular 16 app to Ionic v8, Angular v18, and now I get runtime errors where it looks like it can’t load any of the Ionic components.

If I look into my .angular\cache\18.1.1\vite\deps folder, I do not see anything starting with Ion…

I did go through all the Angular and Ionic upgrade instructions, and it compiles fine, but I get these runtime errors.

I am not sure if this is relevant, but there are also updates to the Angular build…

Ionic info:

$ ionic info

Ionic:

   Ionic CLI                     : 7.2.0 (C:\Users\peter\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 8.2.5
   @angular-devkit/build-angular : 18.1.1
   @angular-devkit/schematics    : 18.1.1
   @angular/cli                  : 18.1.1
   @ionic/angular-toolkit        : 11.0.1

Cordova:

   Cordova CLI       : 11.0.0
   Cordova Platforms : android 13.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 13 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : not installed globally

System:

   NodeJS : v20.15.1 (C:\Program Files\nodejs\node.exe)
   npm    : 10.7.0
   OS     : Windows 10

Would any one have any ideas what is missing here (or how I can further diagnose)?

Thanks in advance

[UPDATE1]

I also notice the following in my terminal

	ng] Application bundle generation complete. [4.600 seconds]
	[ng] Watch mode enabled. Watching for file changes...
	[ng] NOTE: Raw file sizes do not reflect development server per-request transformations.
	[ng] Re-optimizing dependencies because lockfile has changed
	[ng]   ➜  Local:   http://127.0.0.1:8100/
	[ng]   ➜  press h + enter to show help
	[ng] 8:02:56 am [vite] warning: 
	[ng] C:/dev/my-app/.angular/cache/18.1.1/vite/deps/chunk-GQGXXH53.js
	[ng] 900|      return i[n];
	[ng] 901|    }
	[ng] 902|    return import("./".concat(a, ".entry.js").concat("")).then(function(e2) {
	[ng]    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	[ng] 903|      {
	[ng] 904|        cmpModules.set(a, e2);
	[ng] See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.
	[ng]
	[ng]   Plugin: vite:import-analysis
	[ng]   File: C:/dev/my-app/.angular/cache/18.1.1/vite/deps/chunk-GQGXXH53.js?v=e850c948
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-app_8.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-menu_3.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-item_8.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-loading.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-app_8.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-menu_3.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-item_8.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
	[ng] The file does not exist at "C:/dev/my-app/.angular/cache/18.1.1/vite/deps/ion-loading.entry.js" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
1 Like

I am having the same issue, anyone solved this?

I have nothing yet. My next move failing any information is to start again, and select “No” when asked for the new Angular (es) build system . My “guess” is it has something to do with this (due to crowd strike I have to wait till Monday to try this to reboot my remote work machine)

Yes it is the new build system. I had to revert to the old one and it worked again.

1 Like

Ok, yes I also found this…

https://github.com/ionic-team/ionic-framework/issues/28500

I have not converted to standalone yet

I had issues trying to revert, so I will start again.

1 Like

Does this mean I have to convert my app to a standalone if I want to use Angular v17 or higher?

I only get these errors when doing “ionic cap run android -l --external”.

In my case I could still upgrade, just could not use the new build system ( had to stay on the we pack build). But I updated to latest Angular and Ionic, still module based.

1 Like

In the end I upgraded to standalone with the automated migration tool(GitHub - ionic-team/ionic-angular-standalone-codemods) and now I don’t get the error anymore and livereload works.

What I do understand now is that migrating to standalone doesn’t mean that I have to delete my module-files.

I also migrated from Ionic v7, Angular v16 to Ionic 8, Angular v18. Seeing the same issue.
At first, half of my components was the old NgModule. After I convert all of them to the new standalone component, I still see the same problem.
I have tried the tool use recommend… but they seem to produce a broken project? Like, remove IonicModule from the components, import things from @ionic/angular/standalone instead of @ionic/angular? But… still does not work. :\