[英]Nest can't resolve dependencies of the MailerService (?)
I'm trying to configure this module .我正在尝试配置此模块。
The full error message reads as follows:完整的错误消息如下:
Nest can't resolve dependencies of the MailerService (?). Please make sure that the argument MAILER_OPTIONS at index [0] is available in the AppModule context.
I keep getting this error out of nowhere, what MAILER_OPTIONS?我不断收到这个错误,什么MAILER_OPTIONS? Where are those options?
这些选项在哪里? Nothing is said in the documentation in this respect.
在这方面,文档中没有任何说明。 Absolutely no idea what's going on.
完全不知道发生了什么。
Here is my AppModule:这是我的应用模块:
@Module({
imports: [
MailerModule.forRoot({
defaults: {
from: '"No Reply" <noreply@example.com>',
},
template: {
dir: path.join(process.env.PWD, 'templates/pages'),
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
options: {
partials: {
dir: path.join(process.env.PWD, 'templates/partials'),
options: {
strict: true,
},
},
},
}),
],
controllers: [AppController],
providers: [
AppService,
MailerService,
],
})
export class AppModule {}
Any ideas?有任何想法吗?
Here is the service I'm using:这是我正在使用的服务:
@Injectable()
export class AppService {
constructor(
private readonly mailerService: MailerService,
) {}
public async sendEmail(): Promise<any> {
const mailDetail: ISendMailOptions = {
to: 'gutgesagt@yahoo.co.uk',
from: 'noreply@nestjs.com',
subject: 'testing Nest MailerModule',
text: 'test test?!',
html: '<b>Yahooooo</b>',
};
return this.mailerService.sendMail(mailDetail);
}
}
You have to remove the imported MailerService
from the providers
array of your AppModule
.您必须从
AppModule
的providers
数组中删除导入的MailerService
。 Only declare providers that are part of the module itself;仅声明作为模块本身一部分的提供程序; you would never declare an imported provider (service).
您永远不会声明导入的提供者(服务)。
providers: [
AppService,
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.