Skip to content

Application crash when using barrel files (multi index.ts) #1181

@alexandr2110pro

Description

@alexandr2110pro

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

Having

/* InvitationsModule
 *********************** */
import { Module } from '@nestjs/common';
import { InvitationComposerService, InvitationsService } from './services';
import { DatabaseModule } from '../database';
import { AuthModule } from '../auth';
import { MailModule } from '../mail';
import { invitationModelProvider } from './providers';

@Module({
  imports: [
    DatabaseModule.forRoot([invitationModelProvider]),
    AuthModule,
    MailModule,
  ],
  providers: [InvitationsService, InvitationComposerService],
  exports: [InvitationsService],
})
export class InvitationsModule {}

/* AuthModule
 *********************** */
import { Module } from '@nestjs/common';
import { ExternalAuthModule } from '../external-auth';

import { AuthService, ExternalAuthAdapterService } from './services';
import { AuthController } from './auth.controller';
import { AuthMiddleware } from './auth.middleware';

@Module({
  imports: [ExternalAuthModule],
  providers: [AuthService, ExternalAuthAdapterService, AuthMiddleware],
  controllers: [AuthController],
  exports: [AuthService],
})
export class AuthModule {}

where ExternalAuthModule and MailModule have no module imports,

I have this:

screenshot 2018-10-09 19 26 51

which leads to

Error: Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more https://docs.nestjs.com/advanced/circular-dependency.) Scope [TestModule -> InvitationsModule -> AuthModule]

Expected behavior

It should work

Minimal reproduction of the problem with instructions

Not sure. We've got nearly 50 modules and all are working fine.

And most of them actually use AuthModule as you might guess.

Only this one, that I've created recently can't load. Any ideas on what am I doing wrong? :)

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.0.1

Actually, i've got the same is on v4

 
For Tooling issues:
- Node version: 10.10.0  
- Platform:  Mac

Others:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions