Keycloak-angular: AOT Failing on ng build --prod --aot=true

Created on 22 May 2018  路  6Comments  路  Source: mauriciovigolo/keycloak-angular

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search for issues before submitting
- [ ] feature request

Versions.

keycloak-angular 2.0.0
Angular 5.2

Repro steps.

Download and install @2.0.0
Add keycloak module
Add init
run build and note error:

import { BrowserModule } from '@angular/platform-browser';
import {APP_INITIALIZER, NgModule} from '@angular/core';
import { AppComponent } from './app.component';
import { TreasureComponent } from './treasure/treasure.component';
import { LandingComponent } from './landing/landing.component';
import {appRoutes} from './app.routes';
import {HttpClientModule} from '@angular/common/http';
import {KeycloakAngularModule, KeycloakService} from 'keycloak-angular';
import {initializer} from './init';


@NgModule({
  declarations: [
    AppComponent,
    TreasureComponent,
    LandingComponent
  ],
  imports: [
    appRoutes,
    BrowserModule,
    HttpClientModule,
    KeycloakAngularModule
  ],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: initializer,
      multi: true,
      deps: [KeycloakService]
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

./init.ts

import {KeycloakService} from 'keycloak-angular';

export function initializer(keycloak: KeycloakService): () => Promise<any> {
  return (): Promise<any> => {
    return new Promise(async (resolve, reject) => {
      try {
        await keycloak.init();
        resolve();
      } catch (error) {
        reject(error);
      }
    });
  };
}

Next:

ng build --prod --aot=true

Date: 2018-05-22T18:37:13.094Z
Hash: 945915fac13ecc0872fa
Time: 2448ms
chunk {0} styles.ac89bfdd6de82636b768.bundle.css (styles) 0 bytes [initial] [rendered]
chunk {1} polyfills.997d8cc03812de50ae67.bundle.js (polyfills) 84 bytes [initial] [rendered]
chunk {2} main.ee32620ecd1edff94184.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.318b50c57b4eba3d437b.bundle.js (inline) 796 bytes [entry] [rendered]

ERROR in : Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @fish/[email protected] build: `ng build --prod --aot=true`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @fish/[email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jmurphy/.npm/_logs/2018-05-22T18_37_13_120Z-debug.log

Expected: AOT should work

Bug

Most helpful comment

New versions released. All tested and working with aot.
Thanks everybody!

All 6 comments

I am experiencing this issue as well.

Facing the same issue.

Just adding the following line to a fresh angular app is enough to break AOT.
import { KeycloakAngularModule } from 'keycloak-angular';

I can confirm this.

I looked inside the code really quick. I cannot find were the problem is. I will try to have another look when I have more time.

ERROR in : Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.

Confirm same issue with:
keycloak-angular 3.0.0
Angular 6.0.0

Hi, I'm working on this issue.
@rightisleft, thanks for reporting.

New versions released. All tested and working with aot.
Thanks everybody!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samherrmann picture samherrmann  路  3Comments

Wassim24 picture Wassim24  路  4Comments

czeckd picture czeckd  路  4Comments

ValentinBossi picture ValentinBossi  路  4Comments

osafi picture osafi  路  5Comments