Skip to content

Stack overflow in Angular Compiler if an NgModule imports itself #58224

Closed

Description

@RussellSprouts

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

compiler

Is this a regression?

Yes

Description

If an NgModule includes itself as an import, the compiler gets a stack overflow in compiler-cli/src/ngtsc/scope/src/local.ts

import {NgModule} from '@angular/core';

@NgModule({
  imports: [AppModule],
})
export class AppModule {}

Similarly, if there is a circular import:

import {NgModule} from '@angular/core';

@NgModule({
  imports: [AppModule2],
})
export class AppModule1 {}

@NgModule({
  imports: [AppModule1],
})
export class AppModule2 {}

I was able to reproduce this internally with an ng_module build rule, and also in the angular.dev playground. I've given the stack trace and information from the angular.dev playground.

I would expect a diagnostic that circular dependencies are not allowed.

Please provide a link to a minimal reproduction of the bug

https://angular.dev/playground

Please provide the exception or error you saw

✘ [ERROR] Angular compilation initialization failed. [plugin angular-compiler]

getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4358:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4224:32
getExportedScope@file:///home/angular/node_modules/@angular/compiler-cli/bundles/chunk-7SQLBOCA.js:4367:19
getScopeOfModuleReference@file:///home/angular/node_modules/...

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

Angular CLI: 18.1.3
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.1.2
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser

Package Version

@angular-devkit/architect 0.1801.3
@angular-devkit/core 18.1.3
@angular-devkit/schematics 18.1.3
@angular/build 18.1.3
@angular/cli 18.1.3
@schematics/angular 18.1.3
rxjs 7.8.1
typescript 5.5.4

Anything else?

No response

Activity

  1. added
    area: compiler
    on Oct 16, 2024
  2. added this to the needsTriage milestone on Oct 16, 2024
  3. added
    P3
    on Oct 16, 2024
  4. modified the milestones: needsTriage, Backlog on Oct 16, 2024
  5. JoostK commented on Oct 16, 2024

    @JoostK
    Member

    This should be pretty straightforward to resolve, ideally be reporting an error.

  6. self-assigned this
    on Oct 16, 2024
  7. added a commit that references this issue on Oct 18, 2024
    b0ab653
  8. added a commit that references this issue on Oct 18, 2024
    d0c74f3
  9. angular-automatic-lock-bot commented on Nov 18, 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.

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

Metadata

Metadata

Assignees

Labels

P3area: compilerbugstate: has PR

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions