Solvedangular cli ng update did not change my import statements

๐Ÿž Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [X] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No, this behavior did not exist prior to 8.x

Description

ran ng update @angular/cli @angular/core
loadChildren import statements were not updated to new syntax

๐Ÿ”ฌ Minimal Reproduction

I haven't dug into the migration code, but I have my routes in a app-routing.module.ts file:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    pathMatch: 'full',
    loadChildren: './home/home.module#HomeModule',
    data: { depth: 0 },
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
})
export class AppRoutingModule {}

๐Ÿ”ฅ Exception or Error

No error, just old import pattern instead of new.

๐ŸŒ Your Environment

I was on Angular 7.2.15 and this was part of the update process to 8.0.0.

Anything else relevant?
I'm wondering if the migration code is targeting a certain file or something else that would have excluded this file from being updated to the new import pattern.

Here's the last bit from the ng update command:

    ** Executing migrations for package '@angular/core' **
            ------ Static Query Migration ------
            With Angular version 8, developers need to
            explicitly specify the timing of ViewChild and
            ContentChild queries. Read more about this here:
            https://v8.angular.io/guide/static-query-migration
            ------------------------------------------------
UPDATE src/app/search/search.component.ts (2049 bytes)
32 Answers

โœ”๏ธAccepted Answer

A workaround for now is to run the following commands after you are already on Angular and CLI version 8:

ng update @angular/cli --from 7 --to 8 --migrate-only
ng update @angular/core --from 7 --to 8 --migrate-only

Other Answers:

same problem

  • not working auto migrate - ViewChildren()
  • not working auto migrate - router routes

are there any info about the time this will be fixed?

I'm also getting this bug, Angular Material correctly updated my paths etc but my imports did not upgrade and I had to manually do it myself as well as change my module param in the ts.config

@mart2k What happens if you re-run the migrations manually afterwards again?

ng update @angular/cli --from 7 --to 8 --migrate-only
ng update @angular/core --from 7 --to 8 --migrate-only

@alan-agius4 not using an RC or beta.

When I try to manually update the import statements, I'm getting a Typescript error:
Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.ts(1323)

  {
    path: '',
    pathMatch: 'full',
    // loadChildren: './home/home.module#HomeModule',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
    data: { depth: 0 },
  },

Here is my tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

More Issues: