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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52767225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:41:23  来源:igfitidea点击:

"Error: Arguments array must have arguments." AppModule

javascriptnode.jsangulartypescriptnpm

提问by kg123

When running ng serve with a successful compilation in my Angular app, I started getting the following error in the browser console.

在我的 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)

This as far as I can tell from Main.ts platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err));

据我所知 Main.ts platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err));

I have deleted the node modules folder and reinstalled and I'm having trouble with the lack of explanation the error gives. Plus, I'm somewhat new to Angular.

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

Any help would be greatly appreciated.

任何帮助将不胜感激。

EDIT

编辑

I ran ng serve --aotand got the following error

我跑了ng serve --aot,得到以下错误

ERROR in : Error: Internal error: unknown identifier []
 at Object.importExpr$ [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

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

AppComponent Constructor

应用组件构造函数

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

采纳答案by Vivek Kumar

First, try building/serving the app with ng serve --aotflag. Changes are some warning/error will be shown at the compile time.

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

As far as I can think, can you search in your project, if you are importing any component/module

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

like this import {something} from "../node_modules/@somepackage/adfas";instead of import {something} from "@somepackage/adfas";

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



Also can you please share what you have in @NgModule({})decorator, and in AppComponent constructor();

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

I think the angular is not able to provide all the injected dependencies.

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

回答by Jean-Baptiste Martin

I had the same error because of a circular dependency in my code:

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

Service1 > Service2 > Service1

回答by Muhammed Moussa

i had the same issue, just tried to start app again and it worked.

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

回答by vlio20

In my case I was missing the injected typein the constructor :/

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

回答by Johnathan J.

This Typescript snippet demonstrates a scenario which causes this error.

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

...

export class AClassImportingAService {

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

...
}

回答by Vivek Natarajan

I has same error, when @Injectable decorator and export keyword were not used for a dependency.

我有同样的错误,当 @Injectable 装饰器和导出关键字没有用于依赖项时。

回答by John Vandivier

I received this error due to having a circular dependency. I had a store which depended on some initial state which was provided by a service that depended on my store.

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

I resolved the issue by extracting the initial state, which was a constant object, to its own constants file.

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

回答by Lievno

I made a typo instead of ":" I used "," in the constructor and had this error:

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

constructor(private myService, Myservice) {
}

//instead of

constructor(private myService: Myservice) {
}