Skip to content

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

Closed

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

Activity

  1. added
    area: migrations
    cross-cutting: standalone
    on Aug 18, 2023
  2. modified the milestone: needsTriage on Aug 18, 2023
  3. SuneRadich commented on Sep 22, 2023

    @SuneRadich

    I am seeing something similar.

    Tough my setup is different. I run a monorepo powered by nx (nx.dev). I am in the process of converting our libraries to standalone. The first step, of the generator, where I convert the internals of a library to standalone works fine. But when I run the second step (prune-ng-modules) the generator just updates and remove the module, but it does not replace the import with imports of the standalone components.

  4. added
    P3
    on Aug 28, 2024
  5. modified the milestones: needsTriage, Backlog on Aug 28, 2024
  6. self-assigned this
    on Sep 6, 2024
  7. added a commit that references this issue on Sep 6, 2024
    ccd67e9
  8. added a commit that references this issue on Sep 6, 2024
    9895e44
  9. added a commit that references this issue on Sep 6, 2024
    fc95a9a
  10. angular-automatic-lock-bot commented on Oct 7, 2024

    @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.

  11. locked and limited conversation to collaborators on Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: migrationsbugcross-cutting: standalonestate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions