2

Afte upgrading to Angular 9 (from Angular 8) and running ng build I am getting

ERROR in Failed to list lazy routes: Unknown module './src/app/app.module#AppModule'.

It seems that the main app module cannot be found.

This is my main.ts file:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

I have created a new project and was able to run it successfully.

This means that there changed something from 8 to 9.

Any ideas what I have to change?

0

2 Answers 2

4

For lazy loaded modules via the router, make sure you are using dynamic imports. Importing via string is removed in v9. ng update should take care of this automatically. Learn more on angular.io.


In your app-routing.module.ts you shoud be have something like that:

{
        path: '/',
        loadChildren: () => import('src/app/app.module').then(m => m.AppModule)
}
Sign up to request clarification or add additional context in comments.

1 Comment

dynamic imports is not v9 feature, it is there since v8. If that was a case he should get a compilation error but this one is run-time error. Also if you do upgrade like ng update @angular/core the schematics taking care of dynamic importsmigration automatically.
2

Seems like similar issue was being reported here

Possible solution is to set aot: true in angular.json

P.S
See the angular.json difference between CLI v8 and CLI v9

đź’ˇ Migration tip :

  • npm install @angular/cli -g
  • ng update @angular/cli @angular/core

1 Comment

It was indeed a combination of different things. The angular.json and the package.json had to be updated in my case to make everything work again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.