Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serious problem ! #36

Open
pedramaghasian opened this issue Jul 25, 2021 · 3 comments
Open

serious problem ! #36

pedramaghasian opened this issue Jul 25, 2021 · 3 comments

Comments

@pedramaghasian
Copy link

hello,

when i use this package i got this error :

[Nest] 22613  - 07/25/2021, 4:34:24 PM     LOG [InstanceLoader] EventStoreModule dependencies initialized +1ms
[Nest] 22613  - 07/25/2021, 4:34:24 PM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the CommandBus (?). Please make sure that the argument ModuleRef at index [0] is available in the CqrsModule context.

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

Error: Nest can't resolve dependencies of the CommandBus (?). Please make sure that the argument ModuleRef at index [0] is available in the CqrsModule context.

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

    at Injector.lookupComponentInParentModules (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:189:19)
    at Injector.resolveComponentInstance (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:145:33)
    at resolveParam (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:99:38)
    at async Promise.all (index 0)
    at Injector.resolveConstructorParams (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:114:27)
    at Injector.loadInstance (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:47:9)
    at Injector.loadProvider (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/injector.js:69:9)
    at async Promise.all (index 3)
    at InstanceLoader.createInstancesOfProviders (/home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/instance-loader.js:44:9)
    at /home/pedram/my-project/github-samples/nestjs-cqrs-starter/node_modules/@nestjs/core/injector/instance-loader.js:29:13

package.json :

{
  "name": "product-service",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "listen": "nest start --watch --config listener.json",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@akanass/nestjsx-crypto": "^2.0.0",
    "@juicycleff/nestjs-event-store": "^3.1.18",
    "@nestjs/common": "^8.0.4",
    "@nestjs/core": "^8.0.4",
    "@nestjs/cqrs": "^8.0.0",
    "@nestjs/microservices": "^8.0.4",
    "@nestjs/mongoose": "^8.0.0",
    "@nestjs/platform-express": "^8.0.4",
    "amqp-connection-manager": "^3.2.2",
    "amqplib": "^0.8.0",
    "class-validator": "^0.13.1",
    "mongoose": "^5.13.3",
    "nestjs-console": "^6.0.0",
    "node-eventstore-client": "^0.2.18",
    "node-nats-streaming": "^0.3.2",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.6.0",
    "@nestjs/schematics": "^7.3.0",
    "@nestjs/testing": "^7.6.15",
    "@types/express": "^4.17.11",
    "@types/jest": "^26.0.22",
    "@types/node": "^14.14.36",
    "@types/supertest": "^2.0.10",
    "@typescript-eslint/eslint-plugin": "^4.19.0",
    "@typescript-eslint/parser": "^4.19.0",
    "eslint": "^7.22.0",
    "eslint-config-prettier": "^8.1.0",
    "eslint-plugin-prettier": "^3.3.1",
    "jest": "^26.6.3",
    "prettier": "^2.2.1",
    "supertest": "^6.1.3",
    "ts-jest": "^26.5.4",
    "ts-loader": "^8.0.18",
    "ts-node": "^9.1.1",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^4.2.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

my app.module.ts :

import { CqrsModule } from '@nestjs/cqrs';
import { ProductModule } from './product/product.module';
import { Module } from '@nestjs/common';
import { EventStoreModule } from '@juicycleff/nestjs-event-store';
@Module({
  imports: [
    CqrsModule,

    EventStoreModule.register({
      type: 'event-store',
      tcpEndpoint: {
        host: 'localhost',
        port: 1113,
      },
      options: {
        defaultUserCredentials: {
          username: 'admin',
          password: 'changeit',
        },
      },
    }),
    ProductModule,
  ],
})
export class AppModule {}

my product.module.ts :

import { Module } from '@nestjs/common';
import { ProductController } from './controllers/products.controller';
import { ProductRepository } from './repository/product.repository';
import { ProductService } from './services/products.service';
import { ProductsSagas } from './sagas/products.sagas';
import { CommandHandlers } from './commands/handlers';
import { EventHandlers } from './events/handlers';
import { ProductCreatedEvent } from './events/impl/product-created.event';
import { CqrsModule } from '@nestjs/cqrs';
import {
  EventStoreModule,
  EventStoreSubscriptionType,
} from '@juicycleff/nestjs-event-store';


@Module({
  imports: [
    CqrsModule,
    EventStoreModule.registerFeature({
      type: 'event-store',
      featureStreamName: '$svc-product',
      subscriptions: [
        {
          type: EventStoreSubscriptionType.Persistent,
          stream: '$svc-product',
          persistentSubscriptionName: 'product',
        },
      ],
      eventHandlers: {
        ProductCreatedEvent: (data) => new ProductCreatedEvent(data),
      },
    }),
  ],
  controllers: [ProductController],
  providers: [
    ProductService,
    ProductRepository,
    ProductsSagas,
    ...CommandHandlers,
    ...EventHandlers,
  ],
})
export class ProductModule {}
@meodemsao
Copy link

@pedramaghasian i have same error with nestjs 8

@ej31
Copy link

ej31 commented Apr 8, 2022

rm -rf node_modules & npm install

@loagencydev
Copy link

Anyone found a solution already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants