After upgrading from Angular version 8 to 10.
Running the - ng serve command gives me error -
ERROR in node_modules/ngx-tree-select/src/module.d.ts:11:56 - err
It seems this ngx-tree-select library has not evolved with latest Angular versions. Maybe you should open a PR request or an issue on the repo.
Just provide "unknown" as Type-Argument. I had the same issue and I solved it as in the following snippet
export const routingModule: ModuleWithProviders<unknown> = RouterModule.forRoot(
routes
);
The solve for the same error in my Angular 10.1.3 version, was change the param of export to .
With error:
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
After change:
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders<any> = RouterModule.forRoot(appRoutes);
To skip this type error just add in you code:
declare module "@angular/core" {
interface ModuleWithProviders<T = any> {
ngModule: Type<T>;
providers?: Provider[];
}
}
Note: this will fix the type checking and allow to continue - if you will notice other lib to Angular10 inconmpatibilities - you need to ask lib upgrade or found another one.
@user9882419 has the best approach i believe. Here is an example to illustrate what he is saying
export class AppSharedModule {
static forRoot(): ModuleWithProviders<AppSharedModule> {
return {
ngModule: AppSharedModule
};
}
}
One cause of this is upgrading Angular to a newer version (i.e. v10), yet having an older JS library that doesn't play nice and also needs to be updated. In my case I received the following error like the OP:
ERROR in [at-loader] ./node_modules/@ng-bootstrap/ng-bootstrap/popover/popover.module.d.ts:6:23 TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s).
Notice in my instance the particular offending library was called out which was @ng-bootstrap
It indeed was on a much older version:
"@ng-bootstrap/ng-bootstrap": "^2.0.0"
I was able to update the package to version 7.0.0
and the error went away and the application built successfully. The main solution here is don't immediately throw in the fixes recommended here or use <any>
in place of a type. There might just be another package you need to update to bring you app compliant with the version of Angular being used to fix the issue correctly.