【问题标题】:"Error: Arguments array must have arguments." AppModule“错误:参数数组必须有参数。”应用模块
【发布时间】:2019-03-16 23:00:55
【问题描述】:

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

【问题讨论】:

    标签: javascript node.js angular typescript npm


    【解决方案1】:

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

    据我所知,如果你正在导入任何组件/模块,你能在你的项目中搜索

    喜欢这个import {something} from "../node_modules/@somepackage/adfas"; 而不是import {something} from "@somepackage/adfas";


    你也可以分享你在@NgModule({})装饰器和AppComponent constructor()中的东西吗;

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

    【讨论】:

    • ApiService 服务未添加到提供程序中。您能否验证您是否在提供程序数组中添加了?
    • 还分享您在文件顶部添加的导入
    • 将 ApiService 添加到提供程序有助于暴露根本原因`无法解析 ApiService 的所有参数:`。当我删除坏参数时它开始正常工作。谢谢!
    • 一些额外的信息,总是使用--aot--prod标志从编译器那里得到一些帮助,相信我有时这是唯一的救星
    • @VivekKumar 谢谢!这为我节省了很多!
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      此 Typescript sn-p 演示了导致此错误的场景。

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

      【讨论】:

      • 任何类型的服务也会导致这个错误。
      【解决方案4】:

      我有同样的问题,只是尝试再次启动应用程序,它工作。

      【讨论】:

        【解决方案5】:

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

        Service1 > Service2 > Service1
        

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案7】:

            由于存在循环依赖,我收到此错误。我有一个依赖于某些初始状态的商店,该状态由依赖于我的商店的服务提供。

            我通过将作为常量对象的初始状态提取到它自己的常量文件来解决了这个问题。

            【讨论】:

              【解决方案8】:

              我打错了,而不是“:”,我在构造函数中使用了“,”并出现了这个错误:

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

              【讨论】:

                猜你喜欢
                • 2011-12-02
                • 2017-06-24
                • 2020-01-10
                • 2021-07-12
                • 2018-06-01
                • 2022-01-11
                • 2015-05-21
                • 2022-01-27
                • 1970-01-01
                相关资源
                最近更新 更多