Nest: HttpModule incorrectly sets Axios instance, if multiple modules imports HttpModule

Created on 5 Jun 2019  路  13Comments  路  Source: nestjs/nest

Bug Report

I have multiple modules, AppModule and OtherModule.
OtherModule imports HttpModule with config A,
AppModule imports HttpModule with config B and OtherModule

Current behavior

AppModule receives HttpService from OtherModule with config A
(_http://localhost:3000 returns http 500 error, connect ECONNREFUSED 127.0.0.1:80_)

Input Code

Repo: https://github.com/maksimkurb/nest-httpmodule-bug

Expected behavior

AppModule should receive HttpService with config B
(_http://localhost:3000 should return {ok: true}_)

Environment


Nest version: 6.3.0


For Tooling issues:
- Node version: v12.2.0  
- Platform: Windows 

Others:

needs triage

Most helpful comment

When I upgrade from 6.3.0 to 6.3.1 crashed Nest can't resolve dependencies of the CacheInterceptor (?, Reflector). Please make sure that the argument at index [0] is available in the AppModule context.

All 13 comments

Fixed in 6.3.1, thanks for reporting!

When I upgrade from 6.3.0 to 6.3.1 crashed Nest can't resolve dependencies of the CacheInterceptor (?, Reflector). Please make sure that the argument at index [0] is available in the AppModule context.

Is CacheInterceptor's first dependency stated in providers of AppModule or in providers and exports of AppModule imports?

I use nestjs-config@^1.4.0 to config CacheModule

    CacheModule.registerAsync({
      useFactory: config => {
        return config.get('server.cache');
      },
      inject: [ConfigService],
    }),

Can you make a minimal reproduction repo?

Have the same issue that @Diluka but with mongoose module init.
Problem appear from 6.3.1, works perfect in 6.3.0.

@maksimkurb @kamilmysliwiec
comment out those will start like <=6.3.0
https://github.com/nestjs/nest/blob/9b5ddceb1f0df018fe21c4c117d8d39c90eb5602/packages/core/injector/injector.ts#L462-L467

This is the difference between >6.3.0 and <=6.3.0
https://github.com/nestjs/nest/commit/f210ebca2fddecef6b235547498b46fe76b3b9e5#diff-03695d7f859ce8dbde7678750e553570R475

I am using global module

You are right, your sample is crashing even without ConfigModule (I've replaced CacheModule.registerAsync(...) to CacheModule.register()).
Please, open a new issue and mention this because I can't reopen it. Seems this update fixed one bug and created another

Fixed in 6.3.1, thanks for reporting!

I'm not sure about it, but I think this is causing now another problem: When I have two modules which both register Mongoose Schemas with MongooseModule.forFeature() and Module A imports Module B, then I can't use Schemas from Module B in Module A's services / controllers.

Or do we have to export MongooseModule from now on in every module? Or does the mongoose module needs an update?

You have to export MongooseModule.forFeature() in Module B if you wish to use schemas from Module A

Ah ok, thanks! And does this also work for more than two modules? When I export MongooseModule from Model A, B and C, because they need to use the schemas from one another?

And shouldn't the docs be updated, because I think there will be more people having this issue when updating to >= 6.3.1...?

Ah ok, thanks! And does this also work for more than two modules?

Yes

And shouldn't the docs be updated, because I think there will be more people having this issue when updating to >= 6.3.1...?

Docs are up to date. It wasn't a breaking change, but a bug that has been fixed. Everyone who didn't follow the docs can face issues now.

Was this page helpful?
0 / 5 - 0 ratings