liaoliaots / nestjs-redis

Redis module for Nest framework (node.js). Support node-redis & ioredis.
MIT License
388 stars 70 forks source link

Can't resolve dependencies in yarn workspaces #535

Closed tyrkinn closed 1 year ago

tyrkinn commented 1 year ago

In separate project everything works fine, but in yarn workspaces all projects with RedisModule gives error

Expected Behavior

RedisModule should be initialized

Current Behavior

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

Potential solutions:

Steps to Reproduce (for bugs)

Here is my AppModule imports:

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    RMQModule.forRootAsync(getRMQConfig()),
    RedisModule.forRootAsync(getRedisConfig()),
    ...
    ]

// --- getRedisConfig
export const getRedisConfig = (): RedisModuleAsyncOptions => ({
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: async (configService: ConfigService) => ({
    config: {
      host: configService.getOrThrow('SHARED_REDIS_HOST'),
      port: Number(configService.getOrThrow('SHARED_REDIS_PORT')),
      password: configService.getOrThrow('SHARED_REDIS_PASSWORD'),
      db: Number(configService.getOrThrow('SHARED_REDIS_MAIN_DB')),
    },
  }),
});

Your Environment

tyrkinn commented 1 year ago

Solved by adding

  "workspaces": {
    "nohoist": [
      "**/nestjs-redis",
      "**/nestjs-redis/**",
    ]
  },

In each package