Extra config in app.module.ts import fails with aot compiler error

Hi,

I give a try on new AWS template from https://github.com/ionic-team/ionic2-starter-aws, everything looks great.
However, when I try to build prod release by ionic cordova build android --prod --release, error like below appears.

I assume the error roots from here IonicModule.forRoot(MyApp, new AwsConfig().load()) in app.module.ts and it is related to AOT compiler feature. But I haven’t found fix on this.

Anybody has any hint?

Thanks,
Danielle

Error: Error encountered resolving symbol values statically. Calling function 'AwsConfig', 

function calls  are not supported. Consider replacing the function or lambda with a reference to an exported function, 

resolving symbol AppModule in app.module.ts, resolving symbol  AppModule

app.config.ts with AwsConfig defined

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

declare var AWS: any;
declare const aws_mobile_analytics_app_id;
declare const aws_cognito_region;
declare const aws_cognito_identity_pool_id;
declare const aws_user_pools_id;
declare const aws_user_pools_web_client_id;
declare const aws_user_files_s3_bucket;

@Injectable()
export class AwsConfig {
  public load() {

    // Expects global const values defined by aws-config.js
    const cfg = {
      "aws_mobile_analytics_app_id": aws_mobile_analytics_app_id,
      "aws_cognito_region": aws_cognito_region,
      "aws_cognito_identity_pool_id": aws_cognito_identity_pool_id,
      "aws_user_pools_id": aws_user_pools_id,
      "aws_user_pools_web_client_id": aws_user_pools_web_client_id,
      "aws_user_files_s3_bucket": aws_user_files_s3_bucket
    };

    AWS.config.customUserAgent = AWS.config.customUserAgent + ' Ionic';

    return cfg;
  }
}

This code looks extremely weird to me. I don’t understand why anybody would explicitly instantiate an object that is decorated with @Injectable, and why this load() method even exists. I don’t see why they don’t just put it all in the constructor and let DI take care of all of this.

In any event, you can try this:

export function makeAwsConfig(): AwsConfig {
  return new AwsConfig().load();
}

...

IonicModule.forRoot(MyApp, makeAwsConfig)

I assume the code snippet was made by AWS guys instead of Ionioc team :).
I did try the same code as you put here, but the values in cfg is not inserted by IonicModule.forRoot at all.

@rapropos how would you have writen the app.confg.ts and import into @NgModule?

I tried to move the code into app.module.ts, still with the same error.
Anybody else has any idea how I can walk this around?

declare var AWS: any;
declare var aws_mobile_analytics_app_id;
declare var aws_cognito_region;
declare var aws_cognito_identity_pool_id;
declare var aws_user_pools_id;
declare var aws_user_pools_web_client_id;
declare var aws_user_files_s3_bucket;

@NgModule({
  declarations: [
    MyApp,
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp, {
      "aws_mobile_analytics_app_id": aws_mobile_analytics_app_id,
      "aws_cognito_region": aws_cognito_region,
      "aws_cognito_identity_pool_id": aws_cognito_identity_pool_id,
      "aws_user_pools_id": aws_user_pools_id,
      "aws_user_pools_web_client_id": aws_user_pools_web_client_id,
      "aws_user_files_s3_bucket": aws_user_files_s3_bucket
    })
  ],

@danielle113 have you found a solution ?