Nest: RangeError: Maximum call stack size exceeded when importing module

Created on 28 Aug 2019  ·  8Comments  ·  Source: nestjs/nest

Regression

Unexpected RangeError: Maximum call stack size exceeded when importing the same module in conjunction with TypeOrmModule.forRootAsync

Potential Commit/PR that introduced the regression**

Can not say an exact commit

Describe the regression

When importing the same module inside the imports option of a module and also inside the imports options of TypeOrmModule.forRootAsync a RangeError: Maximum call stack size exceeded is thrown

Input Code

Install dependencies

npm i @nestjs/[email protected] @nestjs/[email protected] @nestjs/[email protected] express @nestjs/typeorm typeorm pg rxjs ts-node typescript

index.ts

import { TypeOrmModule } from '@nestjs/typeorm';
import { NestFactory } from '@nestjs/core';
import { Module, Injectable } from '@nestjs/common';

@Injectable()
class ConfigService {
  config() {
    return {
      postgres: { uri: 'postgres://user:pass@localhost:5432/testdb' }
    };
  }
}

@Module({
  exports: [ConfigService],
  providers: [ConfigService]
})
class ConfigModule {}

@Module({
  imports: [
    ConfigModule, // <--- importing the config module for my app
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule], // <--- importing the config module for typeorm
      useFactory(config: ConfigService) {
        return {
          url: config.config().postgres.uri,
          type: 'postgres',
          entities: [],
          synchronize: true
        };
      },
      inject: [ConfigService]
    })
  ]
})
class AppModule {}

async function main() {
  const app = await NestFactory.create(AppModule, {
    // remove logger options when testing on 6.5.3 since it does not behave the same as 6.6.1
    logger: ['verbose', 'log', 'debug', 'warn', 'error'] 
  });

  app.listen(3000);
}

main().catch(err => console.log(err));

Launch the app

node -r ts-node/register/transpile-only index.ts

Expected behavior/code

The app should have started with no error

Environment


Nest version: 6.5.3 -> 6.6.1

For Tooling issues:
- Node version: v11.13.0  
- Platform: Linux (Ubuntu 18.04) 

needs triage type

Most helpful comment

Thanks for reporting. Fixed in 6.6.2. Please, upgrade your modules and let me know if you face any other issues!

All 8 comments

I'm having the same problem

@nestjs/core
v.6.0.1 (I was on this version)
v6.1.0 ✅
v.6.2.0 ✅
v.6.2.3 ✅
v.6.2.4 ✅
v.6.3.0 ✅
v.6.4.0 ✅
v.6.5.0 ✅
v.6.6.0 🚫
v.6.5.3 ✅

all other crucial deps are on 6.6.1

candidate: https://github.com/nestjs/nest/pull/2406

Thanks for reporting. Fixed in 6.6.2. Please, upgrade your modules and let me know if you face any other issues!

Confirmed, 6.6.2 solved the issue. Thanks! ❤️

@kamilmysliwiec still have the issue on 6.6.3

error TS2321: Excessive stack depth comparing types 'MongoRepository<Entity>' and 'Repository<Entity>'.

node_modules/typeorm/repository/MongoRepository.d.ts:45:5 - error TS2321: Excessive stack depth comparing types '(optionsOrConditions?: string | number | Date | ObjectID | FindOneOptions<Entity> | Partial<Entity> | undefined, maybeOptions?: FindOneOptions<Entity> | undefined) => Promise<...>' and '{ (id?: string | number | Date | ObjectID | undefined, options?: FindOneOptions<Entity> | undefined): Promise<Entity | undefined>; (options?: FindOneOptions<Entity> | undefined): Promise<...>; (conditions?: FindConditions<...> | undefined, options?: FindOneOptions<...> | undefined): Promise<...>; }'.

45     findOne(optionsOrConditions?: string | number | Date | ObjectID | FindOneOptions<Entity> | Partial<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity | undefined>;
       ~~~~~~~


Found 2 errors.

error Command failed with exit code 2.

@dyatko The issue is not the same. Could it be related to https://github.com/microsoft/TypeScript/issues/33132?

@leon19 you're right, I've rolled back to TS 3.5.3

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artaommahe picture artaommahe  ·  3Comments

tronginc picture tronginc  ·  3Comments

hackboy picture hackboy  ·  3Comments

rafal-rudnicki picture rafal-rudnicki  ·  3Comments

thohoh picture thohoh  ·  3Comments