Skip to content

Standalone migration doesn't handle imports that alias modules #63913

@mattlewis92

Description

@mattlewis92

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

core

Is this a regression?

No

Description

When an NgModule is imported with an as alias, it is not added to the component imports array when converting to standalone

Steps to reproduce:

gh repo clone mattlewis92/standalone-migration-bug
cd standalone-migration-bug
npm i
ng generate @angular/core:standalone --mode=convert-to-standalone --path=./src/app/foo

Outputs this, where the LegacyModule2 is not added to the imports array of FooComponent

import { Component, NgModule } from '@angular/core';
import { LegacyModule } from '../legacy/legacy1'
import { LegacyModule as LegacyModule2 } from '../legacy/legacy2'

@Component({
    selector: 'foo',
    template: '<legacy1 /> <legacy2 />',
    imports: [LegacyModule] // <-- LegacyModule2 should be imported here
})
export class FooComponent {}

@NgModule({
    imports: [LegacyModule, LegacyModule2, FooComponent],
    exports: [FooComponent]
})
export class FooModule {}

Please provide a link to a minimal reproduction of the bug

https://github.com/mattlewis92/standalone-migration-bug

Please provide the exception or error you saw


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

Angular CLI: 20.3.2
Node: 22.14.0
Package Manager: npm 10.9.2
OS: darwin arm64
    

Angular: 20.3.1
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2003.2
@angular-devkit/core         20.3.2
@angular-devkit/schematics   20.3.2
@angular/build               20.3.2
@angular/cli                 20.3.2
@schematics/angular          20.3.2
rxjs                         7.8.2
typescript                   5.9.2
zone.js                      0.15.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: migrationsIssues related to `ng update`/`ng generate` migrationsopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions