2017-04-06 120 views
0

更新角:只獲得一個模塊未找到錯誤建設時督促

更新到角V4後,我得到以下錯誤(我沒有改變的代碼)。

ERROR in Invalid provider for ErrorHandler in /Users/otusweb/Documents/KeynoteTweet/web/node_modules/@angular/core/core.d.ts. useClass cannot be null. 
     Usually it happens when: 
     1. There's a circular dependency (might be caused by using index.ts (barrel) files). 
     2. Class was used before it was declared. Use forwardRef in this case. 

ERROR in ./src/main.ts 
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/otusweb/Documents/KeynoteTweet/web/src' 
@ ./src/main.ts 4:0-74 
@ multi ./src/main.ts 

原來的問題

我試圖設置自定義的全局錯誤處理程序在我的角度2應用程序發送那些翻車。我跟着https://www.bennadel.com/blog/3138-creating-a-custom-errorhandler-in-angular-2-rc-6.htmhttps://netbasal.com/angular-2-custom-exception-handler-1bcbc45c3230

當我在開發模式下運行,一切都很好。有一次,我建立正式版(NG建立--prod)我得到在瀏覽器中出現以下錯誤:

Error: No ErrorHandler. Is platform module (BrowserModule) included? 

下面是代碼: 錯誤handling.ts

import { RollbarService } from 'angular-rollbar/lib'; 
import { ErrorHandler } from '@angular/core'; 
import { Inject } from "@angular/core"; 
import { Injectable } from "@angular/core"; 
import { isDevMode } from '@angular/core'; 

@Injectable() 
export default class CustomErrorHandler extends ErrorHandler { 
    private rollbar:RollbarService; 

    constructor(rollbar: RollbarService) { 
    // The true paramter tells Angular to rethrow exceptions, so operations like 'bootstrap' will result in an error 
    // when an error happens. If we do not rethrow, bootstrap will always succeed. 
    super(true); 

    this.rollbar = rollbar; 
    } 

    handleError(error: any) : void { 
    if(!isDevMode()) 
    { 
    // send the error to the server 
    this.rollbar.error(error.message, error); 
    } 
    else 
    { 
    console.log("skipping rollbar"); 
    } 

    // delegate to the default handler 
    super.handleError(error); 
    } 
} 

和app.module (不含進口)

@NgModule({ 
    declarations: [ 
     AppComponent, 
     PresentationsComponent, 
     PresentationDetailComponent, 
     SlideDetailComponent, 
     HomeComponent, 
     NotFoundComponent 
    ], 
    imports: [ 
     BrowserModule, 
     FormsModule, 
     HttpModule, 
     AppRoutingModule, 
     InlineEditorModule, 
     RollbarModule.forRoot({ 
     accessToken: 'xxxxxtokenxxxx', 
     }), 
     NgbModule.forRoot() 
    ], 
    providers: [ 
    { provide: ErrorHandler, useClass: CustomErrorHandler }, 
    PresentationService, 
    SlideService, 
    Auth, 
    { 
     provide: AuthHttp, 
     useFactory: authHttpServiceFactory, 
     deps: [ Http, RequestOptions ] 
    }, 
    AuthGuard, 
    LoggedOutGuard], 
    bootstrap: [AppComponent] 
}) 

我錯過了什麼?

回答

1

發現的問題,對我的自定義錯誤處理應用程序模塊中的進口是缺少大括號。 ..

import CustomErrorHandler from './error-handling'; 

而不是

import { CustomErrorHandler } from './error-handling'; 
0

看起來像你的子模塊一個都找不到BrowserModule,嘗試將其添加到像出口:

exports: [ 
    BrowserModule, 
] 
+0

感謝您的建議。剛剛嘗試過,並沒有奏效 – otusweb

相關問題