nestjs-minio-client icon indicating copy to clipboard operation
nestjs-minio-client copied to clipboard

Nest can't resolve dependencies of the MinioService (?)

Open lamasagar opened this issue 3 years ago • 16 comments

Nest can't resolve dependencies of the MinioService (?). Please make sure that the argument minioCfgOptions at index [0] is available in the UsersModule context.

Potential solutions:
- If __minioCfgOptions__ is a provider, is it part of the current UsersModule?
- If __minioCfgOptions__ is exported from a separate @Module, is that module imported within UsersModule?
  @Module({
     imports: [ /* the Module containing __minioCfgOptions__ */ ]
   })
  Error: Nest can't resolve dependencies of the MinioService (?). Please make sure that the argument __minioCfgOptions__ at index [0] is available in the UsersModule context.

lamasagar avatar Feb 12 '22 17:02 lamasagar

I had the same problem today. It appears that you need to do the import: [MinioModule.register(...)] call in every module where you want to use it. So, the advice to register it in app.module only works if you intend to use it only in app.service

kdopen avatar Mar 31 '22 22:03 kdopen

I was expecting it to work like CacheModule - register it once app.module and then inject it into the constructor of any service which needs it.

kdopen avatar Mar 31 '22 22:03 kdopen

Same problem here.

raarts avatar Apr 08 '22 16:04 raarts

Sorry people I will update it today haven’t got much time lately.

On Fri, Apr 8, 2022 at 18:47 Ron Arts @.***> wrote:

Same problem here.

— Reply to this email directly, view it on GitHub https://github.com/djedlajn/nestjs-minio-client/issues/19#issuecomment-1093080993, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEYNEWUCBIH5MHOMLDOF3LVEBPLLANCNFSM5OHGCPHQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

djedlajn avatar Apr 08 '22 16:04 djedlajn

Any Update on this issue. I have the same issue with dependencies of the MinioService

sohana08 avatar Apr 16 '22 15:04 sohana08

Hello,

I have added a new option global so that when you register your module if you pass it will be namespaced to global and thus you won't need to import the Minio module in another module. Available in v1.2.0.

Example

MinioModule.register({
      global: true, <---
      endPoint: '127.0.0.1',
      port: 9000,
      useSSL: false,
      accessKey: 'minioadmin',
      secretKey: 'minioadmin',
})

djedlajn avatar Apr 16 '22 16:04 djedlajn

Screen Shot 2022-04-17 at 3 02 16 PM

Still same error after defining global variable

sohana08 avatar Apr 17 '22 09:04 sohana08

You have to register it in AppModule or somewhere else.

Take a look at https://github.com/djedlajn/minio-ex

Registered MinioModule in AppModule with global set to true and using it as service in Arc controller.

djedlajn avatar Apr 17 '22 09:04 djedlajn

I also encountered this issue. I guess this problem come, when you want the module global with registerAsync.

Twois avatar May 09 '22 19:05 Twois

Same issue here. Any potential update @djedlajn ? The minio-ex link is broken btw

gigouni avatar Aug 19 '22 11:08 gigouni

Hello,

I plan on releasing major update providing built support for v9 nest in which aforementioned issues will be fixed. It may happen today or tomorrow.

On Fri, Aug 19, 2022 at 13:39 GIGOU @.***> wrote:

Same issue here. Any potential update @djedlajn https://github.com/djedlajn ? The minio-ex link is broken btw

— Reply to this email directly, view it on GitHub https://github.com/djedlajn/nestjs-minio-client/issues/19#issuecomment-1220573883, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEYNEWV55NQJAD6UEC7Q5DVZ5W7XANCNFSM5OHGCPHQ . You are receiving this because you were mentioned.Message ID: @.***>

djedlajn avatar Aug 19 '22 11:08 djedlajn

Great news, I've opened PR #25 for a brand new major version, supporting nest v9, addressing all of the mentioned problems and refactoring the overall architecture of the library.

Global configuration examples

    MinioModule.registerAsync({
      useFactory: () => ({
        endPoint: '127.0.0.1',
        port: 9000,
        useSSL: false,
        accessKey: 'ACCESS_KEY',
        secretKey: 'SECRET_KEY',
      }),
      isGlobal: true,
    }),
       MinioModule.register({
      endPoint: '127.0.0.1',
      port: 9000,
      useSSL: false,
      accessKey: 'ACCESS_KEY',
      secretKey: 'SECRET_KEY',
      isGlobal: true,
    }),

We are waiting on @djedlajn to run through the changes and make a new release.

lkaric avatar Aug 23 '22 01:08 lkaric

@kdopen @raarts @gigouni @Twois @sohana08 @lamasagar I've released the new major version (2.0.0), please check out the comment above and the slightly altered docs. Also, I'd appreciate the feedback if the issues are resolved.

lkaric avatar Aug 23 '22 16:08 lkaric

@rejvban

How Would I set up unit tests with netjs-minio-client?

The default generated test with included imports for minio can't resolve the dependency to MinioConfigService:

import { Test, TestingModule } from "@nestjs/testing";
import { AttachmentsService } from "./attachments.service";
import {MinioModule, MinioService} from "nestjs-minio-client";

describe("AttachmentsService", () => {
  let service: AttachmentsService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [MinioModule],
      providers: [AttachmentsService, MinioService],
    }).compile();

    service = module.get<AttachmentsService>(AttachmentsService);
  });

  it("should be defined", () => {
    expect(service).toBeDefined();
  });
});

manuschillerdev avatar Aug 26 '22 05:08 manuschillerdev

@kdopen @raarts @gigouni @Twois @sohana08 @lamasagar I've released the new major version (2.0.0), please check out the comment above and the slightly altered docs. Also, I'd appreciate the feedback if the issues are resolved.

I have been using aws-sdk for minio client credentials till now. Will try with MinioService soon

sohana08 avatar Aug 26 '22 10:08 sohana08

@kdopen @raarts @gigouni @Twois @sohana08 @lamasagar I've released the new major version (2.0.0), please check out the comment above and the slightly altered docs. Also, I'd appreciate the feedback if the issues are resolved.

I've install the 2.0.0 version and I may have missed something but it leads to errors here.

My buckets.module.ts

image

(Roughly translated message: The "register" property does not exist on type MinioModule)

There is an issue with the test file too. An example below

image

And its result

image

Did I miss something?

gigouni avatar Sep 01 '22 13:09 gigouni

Closing as the root issue is resolved, for anyone who branched beyond this, please open a separate one.

lkaric avatar Nov 02 '23 15:11 lkaric