“错误:参数数组必须具有参数。”应用模块

时间:2018-10-11 19:05:14

标签: javascript node.js angular typescript npm

在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.ts platformBrowserDynamic().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:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:21731:27)
 at C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:9988:37
 at Array.map (<anonymous>)
 at InjectableCompiler.depsArray (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:9954:25)
 at InjectableCompiler.factoryFor (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:10018:36)
 at InjectableCompiler.injectableDef (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:10037:42)
 at InjectableCompiler.compile (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:10047:106)
 at C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:21576:90
 at Array.forEach (<anonymous>)
 at AotCompiler._emitPartialModule2 (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:21576:25)
 at C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:21569:48
 at Array.reduce (<anonymous>)
 at AotCompiler.emitAllPartialModules2 (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler\bundles\compiler.umd.js:21568:26)
 at AngularCompilerProgram._emitRender2 (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler-cli\src\transformers\program.js:364:31)
 at AngularCompilerProgram.emit (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@angular\compiler-cli\src\transformers\program.js:236:22)
 at AngularCompilerPlugin._emit (C:\Users\kg\Documents\ang2\ad\UI\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:846:49)

ngModule

@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]
})

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(['/']);
  }

8 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

由于我的代码中存在循环依赖性,所以我遇到了相同的错误:

Service1 > Service2 > Service1

答案 2 :(得分:2)

首先,尝试使用ng serve --aot标志来构建/提供服务。更改是一些警告/错误,将在编译时显示。

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

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


您还可以分享在@NgModule({})装饰器和AppComponent constructor()中拥有的内容吗?

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

答案 3 :(得分:1)

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

此打字稿片段演示了导致此错误的情况。

...

export class AClassImportingAService {

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

...
}

答案 6 :(得分:0)

由于具有循环依赖性,我收到此错误。我有一家商店,该商店依赖于某些初始状态,而该状态是由依赖于我的商店的服务提供的。

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

答案 7 :(得分:0)

我输入错误而不是“:”,我在构造函数中使用了“,”,并且出现此错误:

constructor(private myService, Myservice) {
}

//instead of

constructor(private myService: Myservice) {
}