【问题标题】:Error Nest.js Microservices, can not import module of RabbitMQ错误 Nest.js 微服务,无法导入 RabbitMQ 模块
【发布时间】:2021-05-30 21:33:57
【问题描述】:

这里我有代表 RabbitMQ 客户端模块的单独模块

import { Module } from '@nestjs/common';
import { Transport, ClientsModule } from '@nestjs/microservices';
import { ServiceConfig } from '../config/service.config';
import { RmqSubscriberServiceToken } from '../../constants/token.constant';
import { ConfigModule } from '../config/config.module';

@Module({
  imports: [
    ClientsModule.registerAsync([
      {
        name: RmqSubscriberServiceToken,
        useFactory: (config: ServiceConfig) => ({
          transport: Transport.RMQ,
          options: {
            urls: [
              `amqp://${config.rabbitmq.User}:${config.rabbitmq.Password}@${config.rabbitmq.Host}`,
            ],
            queue: config.rabbitmq.QueueName,
            queueOptions: {
              durable: true,
            },
          },
        }),
        imports: [ConfigModule],
        inject: [ServiceConfig],
      },
    ]),
  ],
})
export class RmqSubscriberModule {}

当我将它导入我的服务模块时,我收到以下错误

Error: Cannot find module '@nestjs/core/helpers/optional-require'
Require stack:
- /home/rharutyunyan/workspace/roulette/node_modules/@nestjs/microservices/nest-microservice.js
- /home/rharutyunyan/workspace/roulette/node_modules/@nestjs/microservices/index.js
- /home/rharutyunyan/workspace/roulette/common/lib/services/rabbitmq/rmq-subscriber.module.js
- /home/rharutyunyan/workspace/roulette/common/lib/services/rabbitmq/index.js

有人能解释一下这里有什么问题吗?

【问题讨论】:

  • @nestjs/core 已安装,对吧?
  • @JayMcDoniel 是的,它已安装,任何想法可能是什么问题,我事件直接将此 clientsModule 导入我的服务模块导入,但它不起作用(

标签: node.js module rabbitmq microservices nestjs


【解决方案1】:

发现问题,问题出在版本上,我的@nestjs/core版本和微服务不一样

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 2017-05-08
    • 2019-10-08
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    相关资源
    最近更新 更多