gpt4 book ai didi

Angular:仅在为产品构建时获取模块未找到错误

转载 作者:太空狗 更新时间:2023-10-29 18:20:25 24 4
gpt4 key购买 nike

更新

更新到 Angular 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

原始问题

我正在尝试在我的 Angular 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

当我在开发模式下运行时,一切正常。一旦我为 prod (ng build --prod) 构建,我在浏览器中收到以下错误:

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

代码如下:错误处理.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]
})

我错过了什么?

最佳答案

发现问题,我的自定义错误处理程序的应用程序模块中的导入缺少大括号...

import  CustomErrorHandler  from './error-handling';

代替

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

关于Angular:仅在为产品构建时获取模块未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43249655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com