Angularを13にアップグレードすると
Angularを11系から13系にアップグレードしました。
するとsrc/app/app-routing.module.ts
でこんなエラーが大量に・・・
Type 'string' is not assignable to type 'LoadChildrenCallback'.ts(2322) router.d.ts(1998, 5): The expected type comes from property 'loadChildren' which is declared here on type 'Route'
Error: src/app/app-routing.module.ts:9:5 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 9 loadChildren: './home/home.module#HomePageModule',
[ng] ~~~~~~~~~~~~
[ng] node_modules/@angular/router/router.d.ts:1998:5
[ng] 1998 loadChildren?: LoadChildren;
[ng] ~~~~~~~~~~~~
[ng] The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:14:5 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 14 loadChildren: './my-page/my-page.module#MyPagePageModule',
[ng] ~~~~~~~~~~~~
[ng] node_modules/@angular/router/router.d.ts:1998:5
[ng] 1998 loadChildren?: LoadChildren;
[ng] ~~~~~~~~~~~~
[ng] The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:16:18 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 16 { path: 'day', loadChildren: './day/day.module#DayPageModule' },
[ng] ~~~~~~~~~~~~
[ng] node_modules/@angular/router/router.d.ts:1998:5
[ng] 1998 loadChildren?: LoadChildren;
[ng] ~~~~~~~~~~~~
[ng] The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:17:22 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
dynamic importの書き方が変わったようです!
app-routing.module.ts
// 古いバージョン
{
path: 'my-page/:id',
loadChildren: './my-page/my-page.module#MyPagePageModule',
},
// 新しいバージョン
{
path: 'my-page/:id',
loadChildren: () => import('./my-page/my-page.module').then(m => m.MyPagePageModule),
},
また、tsconfig.json
も"module": "esnext"
になっているか要確認!
{
...
"compilerOptions": {
...
"module": "esnext"
...
}
}
参考