[ ] Regression
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
vscode shows an error when adding a provider to a module:
ts]
Argument of type '{ providers: { provide: string; useFactory: () => Promise<any>; }[][]; exports: { provide: string...' is not assignable to parameter of type 'ModuleMetadata'.
Types of property 'providers' are incompatible.
Type '{ provide: string; useFactory: () => Promise<any>; }[][]' is not assignable to type 'Provider[]'.
Type '{ provide: string; useFactory: () => Promise<any>; }[]' is not assignable to type 'Provider'.
Type '{ provide: string; useFactory: () => Promise<any>; }[]' is not assignable to type 'FactoryProvider'.
Property 'provide' is missing in type '{ provide: string; useFactory: () => Promise<any>; }[]'.
The app boots fine when npm start
but vscode tells that something is wrong with TS.
Import a provider to a module without error
I have generated a new app with nest cli and took app.module.ts
, cats
and database
folder from this sample: https://github.com/nestjs/nest/tree/master/sample/14-mongoose-base .
Open cats.module.ts
or database.module.ts
in vscode and you should see the error.
[System Information]
OS Version : macOS High Sierra
NodeJS Version : v9.10.1
NPM Version : 5.8.0
[Nest Information]
microservices version : 5.0.0-beta.6
websockets version : 5.0.0-beta.6
mongoose version : 3.0.1
testing version : 5.0.0-beta.6
common version : 5.0.0-beta.6
core version : 5.0.0-beta.6
Have you tried updating to latest RC version? Tag @rc
@kamilmysliwiec same issue with
``` "dependencies": {
"@nestjs/common": "5.0.0",
"@nestjs/core": "5.0.0",
"@nestjs/swagger": "2.0.0",
"@nestjs/typeorm": "3.0.0",
After install with @rc same error (version `5.0.0-rc.4`).
Node version is: `v10.1.0`. Full error for one of the services (running perfectly fine `4.6.6`)
src/modules/config/config.module.ts(5,9): error TS2345: Argument of type '{ components: (typeof ConfigService)[]; providers: (typeof ConfigService)[]; }' is not assignable to parameter of type 'ModuleMetadata'.
Types of property 'providers' are incompatible.
Type '(typeof ConfigService)[]' is not assignable to type 'Provider[] | undefined'.
Type '(typeof ConfigService)[]' is not assignable to type 'Provider[]'.
Type 'typeof ConfigService' is not assignable to type 'Provider'.
Type 'typeof ConfigService' is not assignable to type 'FactoryProvider'.
Property 'provide' is missing in type 'typeof ConfigService'.
```
Although above might by my error. Will check it out in the evening and get back to you.
Solved on my side. In my case one of providers had private constructor(...)
. Don't ask why ;)
@matheusdavidson check if by any chance it's not the case in your code.
@kamilmysliwiec, @ith, upgrading to final V5 solves the problem, thank you.
Actually this still happens with V5.
If you take the 14 sample folders and put in a new app with v5, you'll get errors when importing the providers.
I was able to use injecting the provider directly into the module, but not so good because i can't have separate providers to inject into modules.
@matheusdavidson honestly, I don't understand what do you mean. I took 14 sample app and everything is working fine, 0 compilation errors, no warnings.
I am having the same issue. Was this issue solved ?
[System Information]
OS Version : Windows 10
NodeJS Version : v12.0.0
NPM Version : 6.9.0
[Nest Information]
platform-express version : 6.5.3
common version : 6.5.3
core version : 6.5.3
i took example 14 and did 2 things:
in the app module file imported the user module in the imports array.
in the user module file imported the database module in the imports array with rest operator (...) and this is the place where the error occurs.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Solved on my side. In my case one of providers had
private constructor(...)
. Don't ask why ;)@matheusdavidson check if by any chance it's not the case in your code.