[Solved] Cannot find module while running on device only

ERROR Error: Uncaught (in promise): Error: Cannot find module './pages/login/login.module'
Error: Cannot find module './pages/login/login.module'

Having above error only on device.
Everything working fine in ionic serve

Any idea what’s wrong?

There could be a few things wrong here. First, does this module exist?

I didn’t see anyway declare ./pages/login/login.module
The only place is under app-routing.module.ts

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', loadChildren: './pages/login/login.module#LoginPageModule' },
  { path: 'register', loadChildren: './pages/register/register.module#RegisterPageModule' }];

Everything working just fine in Ionic serve, does it means the module should be existed?

@dodomui under your directory /pages/login/ do you have something like login.module.ts and if so, does the export at the bottom say export class LoginPageModule {}? If not, you’ll have to add that file.

Yeah, the module is there and export as class LoginPageModule
I generate page by ionic CLI, all those code is auto generate by ionic CLI also.

Would it be possible to show more of your code? It’s hard to diagnose without being able to see what you have going on. :slightly_smiling_face:

1 Like

I solved the issue.

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', loadChildren: () => import('./pages/login/login.module').then( m => m.LoginPageModule)}

This is my first Ionic 4 + Typescript project.
Was developing by Ionic 1 previously.

Still feel weird, why the default loadchildren method generate by ionic cli doesn’t work for me.:sweat_smile:

Thanks for your kindly help.

1 Like

Interesting… I’ve never seen this before, but if it works, it works :slightly_smiling_face:

1 Like

I have the same problem with only one module: my hotel.module.ts. The other modules work fine. This module also used to work, without changing anything to it, from one day on another I could not access it anymore.

So i tried the solution above but now I have the error: “Uncaught (in promise): ReferenceError: Cannot access ‘HotelPageModule’ before initialization”.

It’s really frustrating. Can anybody help?

1 Like

Nevermind, i’ve found the solution. In the end, it was a service that the module uses that could not be initialized. I think I’ll revert the changes i’ve made in the Routes and app.config.ts.json (i had to change the target here in order to make the import expression work)

I am getting this with Ionic 5
Every thing was working fine and the next moment I get this error.

I revert to a certain point but noup, nothing.
Really frustrated since I have a deadline on this app and still struggling for the last 2 hours sorting it out