Nest: useValue bugged in latest version

Created on 26 Sep 2019  路  13Comments  路  Source: nestjs/nest

Bug Report

Current behavior

I try to write a dynamic module. Check the gist from 馃檹 @evolkmann. I get a compiler error:

Returned expression type ... is not assigneable to DynamicModule

If you switch to useClass it seamlessly works. What am I doing wrong or is it a bug?

Input Code

https://gist.github.com/evolkmann/1019721d46304df3d8ff7adbca87d8ec

Expected behavior

No compiler error since this should work acc. to official docs and I assume gist worked once.

Possible Solution

It works with

{
 provide: MyLibService,
  useFactory: () => {
  return new MyLibService(type);
 },
}

But it should accept a value too...?

Environment


"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",

For Tooling issues:
- Node version:
"node": "10.16.2"
"npm": "6.10.3"
- Platform: Mac

Others:

needs clarification

All 13 comments

Please, provide a minimal repository which reproduces your issue.

@mambax maybe you can find more clarification from the blog post referencing the gist you mentioned. I don't know if you read it before coming to the gist.

As @kamilmysliwiec mentioned, it is hard to find your specific problem without an explicit example.

Maybe provide some code and I can try to help.

@mambax you might find this blog post helpful.

Hey all
I learned from your posts, I read them before, here is the repo:
https://github.com/mambax/use-value-bug

image
I am still not excluding a layer 8 problem (me) I just don't get what could be wrong :(

This works btw:
image

Hi @mambax, for me your code works fine. The only thing which has to be changed is the app module. You have to call the register() method there.

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';

@Module({
  imports: [
    AuthModule.register({
      type: 'jwt'
    })
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

@evolkmann Thanks for checking. I wonder what is wrong with my IDE then. The register call from you of course is missing, but will it solve the typing error above?

@mambax I don't know, for me there are no errors, with and without the register()-call. I installed the exact dependencies defined in the package-lock.json. I am using VS Code, but IntelliJ should also handle it of course.

@evolkmann thanks for helping out anyway, I don't get what is wrong with that thing 馃槩

馃幒
Turns out, rm -rf .idea does not completely invalidate all caches, weird! I also deleted caches File > Invalidate caches / Restart and now it works. Sorry everyone to bother.

this change for me in the new version 6.7.2.

GraphQLModule.forRootAsync({
      imports: [LoggerModule],
      inject: [LoggerService],
      useFactory: (logger: LoggerService) => {
        return new GqlConfigService(logger).createGqlOptions();
      }
    }),

to

GraphQLModule.forRootAsync({
      imports: [LoggerModule],
      inject: [LoggerService],
      useFactory: (logger: LoggerService) => {
        return new GqlConfigService(logger[0]).createGqlOptions();
      }
    }),

GqlConfigService(logger) -> GqlConfigService(logger[0])

somehow the parameter is injected as an array ?

Can confirm useFactory has stopped working for us where inject is an array.

@angelov-todor @dboskovic just fixed in @nestjs/[email protected]. Thanks for reporting!

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

cojack picture cojack  路  3Comments

mishelashala picture mishelashala  路  3Comments

hackboy picture hackboy  路  3Comments

artaommahe picture artaommahe  路  3Comments

menme95 picture menme95  路  3Comments