NestJS import "forRootAsync" only first one
See original GitHub issueI’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
@Module({
providers: [
DatabaseService,
],
exports: [
DatabaseService,
],
imports: [
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => {
const options = config.get('database.databases.email');
options.name = 'default';
options.entities = [__dirname + '/../app/entities/*.entity{.ts,.js}'];
return options;
},
inject: [ConfigService],
}),
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => {
console.log('I AM IGNORED');
const options = config.get('database.databases.app');
options.name = 'app';
options.entities = [__dirname + '/../app/entities/*.entity{.ts,.js}'];
return options;
},
inject: [ConfigService],
}),
],
})
Expected behavior
Nest only load’s first import. The second one is ignored. The module should load all async modules.
BTW. Maybe it would be better if module can accept array of connection options?
Environment
Nest version: 5.3.7
For Tooling issues:
- Node version: v9.4.0
- Platform: Mac
Others:
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Dynamic modules | NestJS - A progressive Node.js framework
First, we'll define a UsersModule to provide and export a UsersService . ... In other words, dynamic modules provide an API for importing...
Read more >Nest js convert module from forRoot to forRootAsync
First you need to create a new file. For example auth.module-definition.ts . Now in this file we need to create ConfigurableModuleBuilder .
Read more >Creating Dynamic Modules in Nest JS Part-1
In this case, we're going to accept a simple options object with suitable properties, which is the typical case. Lets have a look...
Read more >Database | NestJS - A progressive Node.js framework - Netlify
import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm' ... One-to-one, Every row in the primary table has one and...
Read more >@glcap-forks/typegraphql-nestjs - npm
The first one is TypeGraphQLModule.forRoot() which you should call on your root module, just like with the official GraphQLModule . The only ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
See that
name
: https://github.com/nestjs/typeorm/blob/master/lib/interfaces/typeorm-options.interface.ts should be passed at the same level asuseFactory
in case of the multiple connections.The documentation seems to be wrong as the result of
useFactory
is ignored if there is a config named default.