TYPEORM_ENTITIES not taken into account when calling `TypeOrmModule.forRoot`
hgezim opened this issue · comments
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
TYPEORM_ENTITIES=src/**/*.entity.ts
set as an env variable doesn't seem to be taken into consideration when TypeOrmModule.forRoot
is called with no args.
Expected behavior
I expect value of TYPEORM_ENTITIES
to be taken into account when calling TypeOrmModule.forRoot()
.
It essentially should result in the same result as this:
TypeOrmModule.forRoot(
{
entities: ['src/**/*.entity.ts']
}
)
If TYPEORM_ENTITIES=src/**/*.entity.ts
env is provided.
Minimal reproduction of the problem with instructions
- Create a boilerplate nest project
- Set TYPEORM_ENTITIES as the env variable
- Create a database service like so:
@Module({
imports: [TypeOrmModule.forRoot(
{
entities: ['src/**/*.entity.ts']
}
)],
providers: [DatabaseService],
})
export class DatabaseModule {
constructor() { }
}
- Import it into your main.
- Start the project and note how long this step takes
TypeOrmCoreModule dependencies initialized
- Change database service and pass
{ entities: ['src/**/*.entity.ts'] }
toforRoot
. - Start the project again and note how long
TypeOrmCoreModule dependencies initialized
takes.
What is the motivation / use case for changing the behavior?
I was really perplexed as to why this step in app loading would take forever:
TypeOrmCoreModule dependencies initialized +530848ms
. My env variables were set using the TYPEORM_*
convention and namely:
TYPEORM_ENTITIES=src/**/*.entity.ts
Explicitly passing entities
to forRoot
fixed this:
TypeOrmCoreModule dependencies initialized +457ms
Environment
Nest version: @nestjs/core@6.0.2, @nestjs/typeorm@6.0.0
For Tooling issues:
- Node version: v11.15.0
- Platform: Linux
Others:
You must explicitly set the env variable:
TypeOrmModule.forRoot({
...
entities: process.env. TYPEORM_ENTITIES,
})
This package doesn't check your env variables and we don't plan to add this in the future.