Error: No provider for t

Priyank Gupta picture Priyank Gupta · Nov 20, 2017 · Viewed 18.5k times · Source

I am trying to compile my angular code to production mode via ng build --prod and its successful but in browser I get the error :

ERROR p {__zone_symbol__error: Error: Uncaught (in promise): Error: NullInjectorError: No provider for t!

Error: NullInjectorError:…, …}

where as when I run just ng build then the html works fine.

I have tried several links mentioned on git hub:

https://github.com/angular/angular/issues/19219 https://github.com/angular/angular-cli/issues/6851

Doesn't help much.

Attaching my Package.json file content:

also app.module.ts

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {JasperoAlertsModule} from '@jaspero/ng2-alerts';
// Imports commented out for brevity
import {RouterModule} from '@angular/router';
// Components
import {AppComponent} from './app.component';
import {LoginComponent} from './component/login/login.component';
import {DashboardComponent} from './component/dashboard/dashboard.component';
// Services
import {RecordsService} from './services/records.service';
import {AccountService} from './services/account.service';
import {AuthenticateService} from './services/authenticate.service';
import {FooterComponent} from './component/footer/footer.component';
import {HeaderComponent} from './component/header/header.component';


// Define the routes
const ROUTES = [
  {
    path: '',
    redirectTo: 'login',
    pathMatch: 'full'
  },
  {
    path: 'login',
    component: LoginComponent
  },
  {
    path: 'dashboard',
    component: DashboardComponent
  }
];

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent,
    LoginComponent,
    DashboardComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    BrowserAnimationsModule,
    FormsModule,
    JasperoAlertsModule,
    RouterModule.forRoot(ROUTES) // Add routes to the app
  ],
  providers: [
    RecordsService,
    AccountService,
    AuthenticateService
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Answer

LLai picture LLai · Nov 20, 2017

You are trying to use a service that is not listed in providers of your AppModule. Add the service to a providers list to make it work.