admin管理员组文章数量:1024026
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? 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" <[email protected]>',
},
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: '[email protected]',
from: '[email protected]',
subject: 'testing Nest MailerModule',
text: 'test test?!',
html: '<b>Yahooooo</b>',
};
return this.mailerService.sendMail(mailDetail);
}
}
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? 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" <[email protected]>',
},
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: '[email protected]',
from: '[email protected]',
subject: 'testing Nest MailerModule',
text: 'test test?!',
html: '<b>Yahooooo</b>',
};
return this.mailerService.sendMail(mailDetail);
}
}
Share
Improve this question
edited May 17, 2020 at 12:58
Kim Kern
60.7k20 gold badges219 silver badges214 bronze badges
asked May 17, 2020 at 12:08
good-requestgood-request
252 silver badges7 bronze badges
3 Answers
Reset to default 6You have to remove the imported MailerService
from the providers
array of your AppModule
. Only declare providers that are part of the module itself; you would never declare an imported provider (service).
providers: [
AppService,
],
If you encountered the same error on unit test, maybe you have defined MailerModule in AppModule instead of a separate module, it will make unit test fails because you normally don't import the whole AppModule in unit test. Make sure you defined all the MailerModule
on a separate module, like MailModule
, and import this module in the AppModule
.
@Module({
imports: [
EmailModule
],
controllers: [AppController],
providers: [
AppService,
],
})
export class AppModule {}
and
imports...
@Module({
imports: [
ConfigModule,
MailerModule.forRoot({
defaults: {
from: '"No Reply" <[email protected]>',
},
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,
},
},
},
}),
],
exports: [NestMailerModule],
})
export class EmailModule {}
Then also import the module to your RootTestModule
const module: TestingModule = await Test.createTestingModule({
controllers: [...],
providers: [...],
imports: [EmailModule],
}).pile();
I solve this problem just removing MailerService because it is part of the library in node modules and it work for me
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? 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" <[email protected]>',
},
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: '[email protected]',
from: '[email protected]',
subject: 'testing Nest MailerModule',
text: 'test test?!',
html: '<b>Yahooooo</b>',
};
return this.mailerService.sendMail(mailDetail);
}
}
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? 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" <[email protected]>',
},
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: '[email protected]',
from: '[email protected]',
subject: 'testing Nest MailerModule',
text: 'test test?!',
html: '<b>Yahooooo</b>',
};
return this.mailerService.sendMail(mailDetail);
}
}
Share
Improve this question
edited May 17, 2020 at 12:58
Kim Kern
60.7k20 gold badges219 silver badges214 bronze badges
asked May 17, 2020 at 12:08
good-requestgood-request
252 silver badges7 bronze badges
3 Answers
Reset to default 6You have to remove the imported MailerService
from the providers
array of your AppModule
. Only declare providers that are part of the module itself; you would never declare an imported provider (service).
providers: [
AppService,
],
If you encountered the same error on unit test, maybe you have defined MailerModule in AppModule instead of a separate module, it will make unit test fails because you normally don't import the whole AppModule in unit test. Make sure you defined all the MailerModule
on a separate module, like MailModule
, and import this module in the AppModule
.
@Module({
imports: [
EmailModule
],
controllers: [AppController],
providers: [
AppService,
],
})
export class AppModule {}
and
imports...
@Module({
imports: [
ConfigModule,
MailerModule.forRoot({
defaults: {
from: '"No Reply" <[email protected]>',
},
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,
},
},
},
}),
],
exports: [NestMailerModule],
})
export class EmailModule {}
Then also import the module to your RootTestModule
const module: TestingModule = await Test.createTestingModule({
controllers: [...],
providers: [...],
imports: [EmailModule],
}).pile();
I solve this problem just removing MailerService because it is part of the library in node modules and it work for me
本文标签: javascriptNest can39t resolve dependencies of the MailerService ()Stack Overflow
版权声明:本文标题:javascript - Nest can't resolve dependencies of the MailerService (?) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745495546a2153148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论