The feature with the schematic to clean up unused imports duplicates the import array · Issue #59466 · angular/angular · GitHub
Skip to content

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

Closed

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?

Activity

  1. added this to the needsTriage milestone on Jan 10, 2025
  2. crisbeto commented on Jan 10, 2025

    @crisbeto
    Member

    Should be fixed by #59452.

  3. angular-automatic-lock-bot commented on Feb 10, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  4. locked and limited conversation to collaborators on Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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