angulartypescriptangular2-aot

"Invalid provider for the NgModule" when using AoT


Without AoT everything works fine. But after switching loaders, I am getting this error and have no clue how to fix it, or what exactly is wrong.

Invalid provider for the NgModule 'AppModule in /xxx/src/app/app.module.ts' - only instances of Provider and Type are allowed, got: [LoggerService in /xxx/src/app/services/logger-service.service.ts, LocalStorageService in /xxx/node_modules/angular-2-local-storage/dist/local-storage.service.d.ts, WindowService in /xxx/src/app/services/window.service.ts, ?null?, ...]

Related code from AppModule:

import CustomHttp from './services/custom-http.service';

...

@NgModule({

...

  providers: [
    LocalStorageService,
    WindowService,
    AuthService,
    LoggerService,
    CustomHttp,
    AuthTokenStore,
    AuthService,
    SchemaValidator,
    AuthInterceptor,
    DataService,
    ErrorHelper,
    FileUpload,
    {provide: ErrorHandler, useClass: LoggingErrorHandler},
    NonAngularDialogsHelper,
    ConfirmationService,
    SearchHelper,
    FormHelper,
    DebugHelper,
    PuxApplication,
    StoreUtils,
    TranslationHelper,
    MessagesService,
    CustomValidatorsService,
    GeolocationService,
    SavedSearchesService,
    LoggedInfoService,
    BeTranslate,
    CountryHelper,
    SuggestionGenerators,
    PrimeNgHelper,
    UrlHelper,
    DocumentClickService,
    NavigationHelper,
    BeErrorsInterceptor,
    DocumentService,
    ScrollHelper,
    LinkDialogHelper,
    HtmlUtilsService,
    RouterHelperService,
    StripeService,
    VatExamplesService,
    ContactInfoHelper,
    WizardHelper,
    PasswordChangingPagesHelper,
    LandingPageHelper,
    TrackingEventsHelper,
    RfoHelper,
    ReactiveFormsHelper,
    LiveChatService,

    CounterActions
  ]

...

Snippets from CustomHttp:

...

@Injectable()
export default class CustomHttp {

...

  constructor(private http: Http,
              loggerService: LoggerService) {
    this.logger = loggerService.createLogger('CustomHttp');
  }

...

Edit 1: Added whole providers array as requested.


Solution

  • AoT compiler is not very clever. Turns out that it can't handle default imports for some reason...

    Not working:

    import CustomHttp from './services/custom-http.service';
    

    Working:

    import { CustomHttp } from './services/custom-http.service';