Skip to content

standalone migration's prune-ng-modules mode doesn't update standalone imports #51420

@yjaaidi

Description

@yjaaidi

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

core

Is this a regression?

No

Description

Standalone migration's prune-ng-modules doesn't update imports properly when the pruned NgModule is referenced by a standalone component.

The following code:

@Component({
  standalone: true,
  template: `<app-child/>`,
  imports: [ChildModule]
})
class App {
}

@Component({
  selector: 'app-child',
  standalone: true,
  template: `...`,
})
class Child {
}

@NgModule({
  imports: [Child],
  exports: [Child]
})
class ChildModule {}

produces:

@Component({
  standalone: true,
  template: `<app-child/>`,
  imports: []
})
class App {
}

@Component({
  selector: 'app-child',
  standalone: true,
  template: `...`,
})
class Child {
}

and breaks the app, while it should produce:

@Component({
  standalone: true,
  template: `<app-child/>`,
  imports: [Child]
})
class App {
}

@Component({
  selector: 'app-child',
  standalone: true,
  template: `...`,
})
class Child {
}

Please provide a link to a minimal reproduction of the bug

https://github.com/yjaaidi/experiments/tree/repro-prune-ng-modules-standalone

Please provide the exception or error you saw

No response

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

Angular CLI: 16.2.0
Node: 20.0.0 (Unsupported)
Package Manager: pnpm 8.6.2
OS: darwin x64

Angular: 16.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.0
@angular-devkit/build-angular   16.2.0
@angular-devkit/core            16.2.0
@angular-devkit/schematics      16.2.0
@schematics/angular             16.2.0
rxjs                            7.8.0
typescript                      5.1.3
zone.js                         0.13.0

Anything else?

No response

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: migrationsIssues related to `ng update`/`ng generate` migrationsbugcross-cutting: standaloneIssues related to the NgModule-less worldstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions