这里我有一个单独的模块,代表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版本与微服务不同