question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS error on adding provider to a module

See original GitHub issue

I’m submitting a…


[ ] 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.

Current behavior

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.

Expected behavior

Import a provider to a module without error

Minimal reproduction of the problem with instructions

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.

Environment


[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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
ithcommented, May 14, 2018

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.

0reactions
lock[bot]commented, Nov 24, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Provider configuration not present - Hashicorp Support
This occurs when a provider configuration is removed while objects created by that provider still exist in the state. Re-add the provider ...
Read more >
angular - 'No provider' error (even though I've added a provider)
- I've added the Service and AppModule code. My index.ts file only contains export * from './app.component'; and export * from './app.
Read more >
Add Provider to app.module.ts so is persistent across all ...
I have a DataService provider for connecting to a database. I store some data retrieved in that Provider Service. When I use ionic...
Read more >
Common errors - FAQ - A progressive Node.js framework
The most common culprit of the error, is not having the <provider> in the module's providers array. Please make sure that the provider...
Read more >
Singleton services - Angular
If a module defines both providers and declarations (components, directives, pipes), then loading the module in multiple feature modules would duplicate the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found