nestjs-notifications icon indicating copy to clipboard operation
nestjs-notifications copied to clipboard

Nest can't resolve dependencies of the NestJsNotificationsService

Open CamiloManrique opened this issue 3 years ago • 8 comments

I'm running into this error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the NestJsNotificationsService (?, NESTJS_NOTIFICATIONS_QUEUE, NESTJS_NOTIFICATIONS_JOB_OPTIONS). Please make sure that the argument ModuleRef at index [0] is available in the NestJsNotificationsModule context.

Potential solutions:
- If ModuleRef is a provider, is it part of the current NestJsNotificationsModule?
- If ModuleRef is exported from a separate @Module, is that module imported within NestJsNotificationsModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

My code:

app.module.ts

import { Module } from '@nestjs/common';
import {NestJsNotificationsModule} from "nestjs-notifications";
import AppService from "./app.service";

@Module({
    imports: [
      NestJsNotificationsModule.forRoot({}),
    ],
    providers: [
        AppService
    ]
})
export class AppModule {}

app.service.ts

import { Injectable } from "@nestjs/common";
import {LocalizationUpdateNotification} from "./modules/localization/notifications/localization-update.notification";
import {NestJsNotificationsService} from "nestjs-notifications";

@Injectable()
export default class AppService {

    private subscriptions: string[];

    constructor(private readonly notifications: NestJsNotificationsService) {
        this.subscriptions = [];
    }

    addSubscription(id: string) {
        this.subscriptions.push(id);
    }

    async sendNotifications(id, event) {
        if (this.subscriptions.includes(id)) {
            const notification = new LocalizationUpdateNotification({ id, event });
            await this.notifications.send(notification);
        }
    }
}

CamiloManrique avatar Sep 09 '21 04:09 CamiloManrique

Any solutions?

houssenedao avatar Sep 30 '21 16:09 houssenedao

Any news?

raqso avatar Dec 23 '21 13:12 raqso

I believe this because @nestjs/core is listed as a hard dependency

https://github.com/edstevo/nestjs-notifications/blob/2e3da4320342719a63dd751a3fd9d958177ea61d/package.json?#L42

You guys need to make this

.
├── package.json
├── src
└── node_modules
    ├── @nestjs
    │   ├── core
    │   └── common
    └── nestjs-notifications
        └── node_modules
            └── @nestjs
                ├── core
                └── common

looks like this instead:

.
├── package.json
├── src
└── node_modules
    ├── @nestjs
    │   ├── core
    │   └── common
    └── nestjs-notifications
        └── node_modules

micalevisk avatar Dec 27 '21 15:12 micalevisk

I believe this because @nestjs/core is listed as a hard dependency

https://github.com/edstevo/nestjs-notifications/blob/2e3da4320342719a63dd751a3fd9d958177ea61d/package.json?#L42

You guys need to make this

.
├── package.json
├── src
└── node_modules
    ├── @nestjs
    │   ├── core
    │   └── common
    └── nestjs-notifications
        └── node_modules
            └── @nestjs
                ├── core
                └── common

looks like this instead:

.
├── package.json
├── src
└── node_modules
    ├── @nestjs
    │   ├── core
    │   └── common
    └── nestjs-notifications
        └── node_modules

I've tried this, but the error is still the same. 🤷‍♂️

raqso avatar Dec 28 '21 09:12 raqso

@raqso are you using NestJS v7?

micalevisk avatar Dec 28 '21 11:12 micalevisk

@raqso are you using NestJS v7?

No, 8 :/

raqso avatar Dec 28 '21 14:12 raqso

could be that, even tho the peer deps allows v8

micalevisk avatar Dec 28 '21 15:12 micalevisk

Any news? I have the same error in Nestjs 8 :/

jmuller-oct avatar Mar 09 '22 19:03 jmuller-oct