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.

RangeError: Maximum call stack size exceeded when importing module

See original GitHub issue

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) 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
kamilmysliwieccommented, Aug 28, 2019

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

2reactions
kgajowycommented, Aug 28, 2019

Confirmed, 6.6.2 solved the issue. Thanks! ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 7 error RangeError: Maximum call stack size exceeded
1.This error occur when there is an infinite loop. As you have mentioned that the page loads when app-heroes is commented, this might...
Read more >
Maximum Call Stack Size Exceeded (Typescript Error) - Medium
Scenario for Maximum Call Stack Size Exceeded Error. In your code, the possibility is, You are calling a function that is calling another...
Read more >
Uncaught RangeError: Maximum call stack size exceeded
This error is almost always means you have a problem with recursion in JavaScript code, as there isn't any other way in JavaScript...
Read more >
Maximum call stack size exceeded · Issue #1289 - Angular 10
Whenever I try to run ng serve , I get an ERROR RangeError: Maximum call stack size exceeded error and my project basically...
Read more >
RangeError: Maximum call stack size exceeded - Educative.io
In this shot, we will see how to fix the “RangeError: Maximum call stack size exceeded” error. ... The most common source for...
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