goo*_*est 1 javascript dependency-injection node.js typescript nestjs
我正在尝试配置这个模块。
完整的错误消息如下:
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.
我总是莫名其妙地收到此错误,什么 MAILER_OPTIONS?这些选项在哪里?文档中没有提及这方面的内容。完全不知道发生了什么。
这是我的应用程序模块:
@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 {}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这是我正在使用的服务:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
您必须MailerService从. 仅声明属于模块本身一部分的提供程序;您永远不会声明导入的提供者(服务)。providersAppModule
providers: [
AppService,
],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3013 次 |
| 最近记录: |