Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded when importing module #2834

Closed
leon19 opened this issue Aug 28, 2019 · 8 comments
Closed

RangeError: Maximum call stack size exceeded when importing module #2834

leon19 opened this issue Aug 28, 2019 · 8 comments
Labels
needs triage This issue has not been looked into type: bug 😭

Comments

@leon19
Copy link

leon19 commented Aug 28, 2019

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/common@6.6.1 @nestjs/core@6.6.1 @nestjs/platform-express@6.6.1 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) 

@leon19 leon19 added needs triage This issue has not been looked into type: bug 😭 labels Aug 28, 2019
@dolsem
Copy link

dolsem commented Aug 28, 2019

I'm having the same problem

@kgajowy
Copy link

kgajowy commented Aug 28, 2019

@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: #2406

@kamilmysliwiec
Copy link
Member

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

@kgajowy
Copy link

kgajowy commented Aug 28, 2019

Confirmed, 6.6.2 solved the issue. Thanks! ❤️

@dyatko
Copy link

dyatko commented Aug 29, 2019

@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.

@leon19
Copy link
Author

leon19 commented Aug 29, 2019

@dyatko The issue is not the same. Could it be related to microsoft/TypeScript#33132?

@dyatko
Copy link

dyatko commented Aug 29, 2019

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

@lock
Copy link

lock bot commented Nov 27, 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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into type: bug 😭
Projects
None yet
Development

No branches or pull requests

5 participants