"Error: Arguments array must have arguments."应用模块



在我的 Angular 应用程序中成功编译运行 ng serve 时,我开始在浏览器控制台中收到以下错误。

AppComponent_Host.ngfactory.js? [sm]:1 ERROR Error: Arguments array must have arguments.
at injectArgs (core.js:1412)
at core.js:1491
at _callFactory (core.js:8438)
at _createProviderInstance (core.js:8396)
at resolveNgModuleDep (core.js:8371)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get
(core.js:9064)
at resolveDep (core.js:9429)
at createClass (core.js:9309)
at createDirectiveInstance (core.js:9186)
at createViewNodes (core.js:10406)

据我所知,这是从Main.tsplatformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err));

我已经删除了节点模块文件夹并重新安装,并且由于错误给出的解释缺乏问题而遇到问题。另外,我对Angular有点陌生。

任何帮助将不胜感激。

编辑

我运行了ng serve --aot并收到以下错误

ERROR in : Error: Internal error: unknown identifier []
at Object.importExpr$$1 [as importExpr] (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:21731:27)
at C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:9988:37
at Array.map (<anonymous>)
at InjectableCompiler.depsArray (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:9954:25)
at InjectableCompiler.factoryFor (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:10018:36)
at InjectableCompiler.injectableDef (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:10037:42)
at InjectableCompiler.compile (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:10047:106)
at C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:21576:90
at Array.forEach (<anonymous>)
at AotCompiler._emitPartialModule2 (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:21576:25)
at C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:21569:48
at Array.reduce (<anonymous>)
at AotCompiler.emitAllPartialModules2 (C:UserskgDocumentsang2adUInode_modules@angularcompilerbundlescompiler.umd.js:21568:26)
at AngularCompilerProgram._emitRender2 (C:UserskgDocumentsang2adUInode_modules@angularcompiler-clisrctransformersprogram.js:364:31)
at AngularCompilerProgram.emit (C:UserskgDocumentsang2adUInode_modules@angularcompiler-clisrctransformersprogram.js:236:22)
at AngularCompilerPlugin._emit (C:UserskgDocumentsang2adUInode_modules@ngtoolswebpacksrcangular_compiler_plugin.js:846:49)

ng模块

@NgModule({
declarations: [
AppComponent,
LoginComponent,
ItemDashboardComponent,
UnprotectedSearchComponent,
HomeComponent,
UnprotectedResultsComponent,
DashboardComponent,
TrackingListComponent,
ListItemComponent,
ActionItemComponent,
ActionListComponent,
ItemInfoTableComponent,
TrackingInfoTableComponent,
FilterPipe,
RegisterItemsComponent,
RegisterPackageComponent,
AddItemsPackageComponent,
ChangeCustodyComponent,
CheckTempComponent,
RemoveItemsComponent,
ScannerComponent,
ContainerDashboardComponent,
SoldComponent
],
imports: [
NgQrScannerModule,
MatTabsModule,
AngularFontAwesomeModule,
MatListModule,
MatFormFieldModule,
BrowserAnimationsModule,
MatMenuModule,
MatProgressBarModule,
BrowserModule,
MatIconModule,
MatGridListModule,
AngularFontAwesomeModule,
FormsModule,
AppRoutingModule,
HttpClientModule,
RouterModule.forRoot([
{
path: 'home',
component: HomeComponent
},
//{path: 'openSearch', component: LoginComponent},
{
path: 'item',
component: ItemDashboardComponent,
canActivate: [AuthGuard, ManufacturerAuthGuardService]
},
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [AuthGuard]
},
{
path: 'unprotectedResults',
component: UnprotectedResultsComponent,
canActivate: [AuthGuard]
},
{
path: 'trackingList/'+environment.config.itemWorkflow+'/:contractId',
component: ItemDashboardComponent,
canActivate: [AuthGuard]
},
{
path: 'trackingList/'+environment.config.packageWorkflow+'/:contractId',
component: ContainerDashboardComponent,
canActivate: [AuthGuard]
},
{
path: 'trackingList',
component: TrackingListComponent,
canActivate: [AuthGuard]
},
{
path: 'actions',
component: ActionListComponent,
canActivate: [AuthGuard]
},
{
path: 'publicResults/:contractId',
component: UnprotectedResultsComponent
},
{
path: 'registerItems',
component: RegisterItemsComponent,
canActivate: [AuthGuard]
},
{
path: 'addItemsToPackage',
component: AddItemsPackageComponent,
canActivate: [AuthGuard]
},
{
path: 'registerPackage',
component: RegisterPackageComponent,
canActivate: [AuthGuard]
},
{
path: 'changeCustody/:contractId',
component: ChangeCustodyComponent,
canActivate: [AuthGuard]
},
{
path: 'changeCustody',
component: ChangeCustodyComponent,
canActivate: [AuthGuard]
},
{
path: 'checkTemp',
component: CheckTempComponent,
canActivate: [AuthGuard]
},
{
path: 'removeItems',
component: RemoveItemsComponent,
canActivate: [AuthGuard]
},
{
path: 'sellItems',
component: SoldComponent,
canActivate: [AuthGuard]
},

]),
UiModule
],
providers: [
AuthGuard,
{
provide: HTTP_INTERCEPTORS,
useClass: MyInterceptor,
multi: true
},
MockBackend,
fakeBackendProvider,
BaseRequestOptions,
AuthGuard,
AdminAuthGuard,
AdalService,
SoldComponent
],
bootstrap: [AppComponent]
})

应用组件构造函数

constructor(private api: ApiService, private adalService: AdalService, private _http: HttpClient, private router: Router, public authService: AuthService) {
this.adalService.init(environment.config);
if (!this.adalService.userInfo.authenticated) this.router.navigate(['/']);
}

首先,尝试使用ng serve --aot标志构建/提供应用程序。编译时可能会显示一些警告/错误。

据我所知,如果您要导入任何组件/模块,您可以在项目中搜索吗

像这样import {something} from "../node_modules/@somepackage/adfas";而不是import {something} from "@somepackage/adfas";


您能否分享您在@NgModule({})装饰器和AppComponent constructor()中拥有的内容;

我认为角度无法提供所有注入的依赖项。

由于代码中的循环依赖关系,我遇到了同样的错误:

Service1 > Service2 > Service1

我遇到了同样的问题,只是尝试再次启动应用程序并且它起作用了。

就我而言,我在构造函数中缺少注入的类型:/

此 Typescript 代码段演示了导致此错误的场景。

...
export class AClassImportingAService {
constructor(private _importedService) {
// ERROR: notice there is no type on _importedService
//   It should read 'private _importedService: ImportedService'
}
...
}

当装饰器和导出关键字未用于依赖项时@Injectable我遇到了同样的错误。

由于具有循环依赖关系,我收到了此错误。我有一家商店,它依赖于一些初始状态,该状态由依赖于我的商店的服务提供。

我通过将初始状态(这是一个常量对象(提取到其自己的常量文件中来解决此问题。

我做了一个错别字而不是":",我在构造函数中使用了","并出现了此错误:

constructor(private myService, Myservice) {
}
//instead of
constructor(private myService: Myservice) {
}

最新更新