没有AoT一切正常。但是在切换加载器之后,我收到了这个错误并且不知道如何解决它,或者究竟是什么问题。
中的NgModule' AppModule的提供程序无效 /xxx/src/app/app.module.ts' - 仅提供者和类型的实例 允许,得到:[LoggerService in /xxx/src/app/services/logger-service.service.ts,LocalStorageService 在 /xxx/node_modules/angular-2-local-storage/dist/local-storage.service.d.ts, /xxx/src/app/services/window.service.ts中的WindowService,?null?,...]
来自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
]
...
来自CustomHttp
的小部件:
...
@Injectable()
export default class CustomHttp {
...
constructor(private http: Http,
loggerService: LoggerService) {
this.logger = loggerService.createLogger('CustomHttp');
}
...
编辑1:根据请求添加了整个提供者数组。
答案 0 :(得分:5)
AoT编译器不是很聪明。事实证明它出于某种原因无法处理默认导入......
不工作:
import CustomHttp from './services/custom-http.service';
工作:
import { CustomHttp } from './services/custom-http.service';
答案 1 :(得分:0)
对我来说,我在服务的index.ts文件中包含了某些服务的重复导出语句。终于,在删除了一个之后就可以了。
(您可以使用Excel查找重复项。:-))
从此link
.....
export * from './custom-message.service';
export * from './department.service';
export * from './custom-message.service'; // duplicated, remove this
.......