Skip to content

The feature with the schematic to clean up unused imports duplicates the import array #59466

@amanplans

Description

@amanplans

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

I created a new project and upgraded it to Angular 19.1.0-rc.0 to try out the new schematic to clean up unused imports. After running the command, the imports array got duplicated.

#59353

Please provide a link to a minimal reproduction of the bug

https://github.com/amanplans/cleanup-unused-imports

Please provide the exception or error you saw

I added an unused import in app.component.ts and ran the command `ng g @angular/core:cleanup-unused-imports` and the imports array got duplicated.

**Before:**
`
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { UnusedComponent } from './unused.component';

@Component({
    selector: 'app-root',
    imports: [RouterOutlet, UnusedComponent],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'cleanup-unused-imports';
}
`

**After:**
`
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';


@Component({
    selector: 'app-root',
    imports: [RouterOutlet][RouterOutlet],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'cleanup-unused-imports';
}
`

The line with imports contains two arrays of [RouterOutlet] instead of one.

Please provide the environment you discovered this bug in (run ng version)

@angular-devkit/architect       0.1901.0-rc.0
@angular-devkit/build-angular   19.1.0-rc.0
@angular-devkit/core            19.1.0-rc.0 (cli-only)
@angular-devkit/schematics      19.1.0-rc.0
@schematics/angular             19.1.0-rc.0
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.15.0

Anything else?

Is this something for @crisbeto?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: migrationsIssues related to `ng update`/`ng generate` migrations

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions