ng build fails after injecting Keycloak, but ng serve works fine · Issue #59837 · angular/angular · GitHub
Skip to content

ng build fails after injecting Keycloak, but ng serve works fine #59837

Closed

Description

@ADegele

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

compiler, compiler-cli

Is this a regression?

Yes

Description

I have recently upgraded to Angular 19 and the corresponding keycloak-angular module. After replacing the legacy KeycloakService with Keycloak, ng serve works fine, but ng build failes with an error during AotCompilation: TypeError: Cannot read properties of undefined (reading 'Symbol(patchedReferencedAliases)')

Please find attached our project. I have taken our project and deleted most parts of it, but the bug is still reproducible. I have left some stuff that i could not easily delete.
frontend.zip

npm install
npx ng serve # works
npx ng build # error

Please provide a link to a minimal reproduction of the bug

https://github.com/user-attachments/files/18639967/frontend.zip

Please provide the exception or error you saw

$ npx ng build
Application bundle generation failed. [1.933 seconds]

X [ERROR] Angular compilation emit failed. [plugin angular-compiler]

  TypeError: Cannot read properties of undefined (reading 'Symbol(patchedReferencedAliases)')
      at loadIsReferencedAliasDeclarationPatch (file:///C:/tmp/frontend/node_modules/@angular/compiler-cli/bundles/chunk-WKHF7UQD.js:1568:49)
      at file:///C:/tmp/frontend/node_modules/@angular/compiler-cli/bundles/chunk-WKHF7UQD.js:1623:35
      at transformation (C:\tmp\frontend\node_modules\typescript\lib\typescript.js:118855:14)
      at transformNodes (C:\tmp\frontend\node_modules\typescript\lib\typescript.js:118863:70)
      at Object.transform (C:\tmp\frontend\node_modules\typescript\lib\typescript.js:152762:18)
      at AotCompilation.emitAffectedFiles (C:\tmp\frontend\node_modules\@angular\build\src\tools\angular\compilation\aot-compilation.js:272:58)
      at emit (C:\tmp\frontend\node_modules\@angular\build\src\tools\angular\compilation\parallel-worker.js:95:37)
      at C:\tmp\frontend\node_modules\piscina\dist\worker.js:144:32

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

Angular CLI: 19.1.5
Node: 20.18.0
Package Manager: npm 11.1.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.5
@angular-devkit/build-angular   19.1.5
@angular-devkit/core            19.1.5
@angular-devkit/schematics      19.1.5
@angular/cli                    19.1.5
@schematics/angular             19.1.5
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else?

I found a workaround to make the project build again: Replace the constructor-injection of keycloak: Keycloak with property-injection private keycloak: Keycloak = inject(Keycloak) outside of the constructor.
Replace (search for keycloak: Keycloak, 3 locations):

  constructor(
    private benutzerInfoService: BenutzerInfoService,
    private keycloak: Keycloak
  ) {

With this workaround:

  private keycloak: Keycloak = inject(Keycloak);
  constructor(
    private benutzerInfoService: BenutzerInfoService
  ) {

Since property-injection and constructor-injection should conceptionally be the same, I fear this bug might resurface and bite us later, therefore I am not satisfied with this workaround.

Activity

  1. added this to the needsTriage milestone on Feb 3, 2025
  2. michalma commented on Feb 3, 2025

    @michalma

    @ADegele Same here, I also encountered this problem and have been struggling with it for the last two days. I didn't suspect it was about Keycloak. Thanks for the workaround, you saved me another hours of debugging!

  3. yeahitsjan commented on Feb 5, 2025

    @yeahitsjan

    Same problem here. Sent here from my report in angular-cli. Setting isolatedModules: false inside the tsconfig.json also works around the issue.

  4. self-assigned this
    on Feb 6, 2025
  5. added a commit that references this issue on Feb 13, 2025
    16fc074
  6. added a commit that references this issue on Feb 13, 2025
    973033a
  7. angular-automatic-lock-bot commented on Mar 16, 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.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions