email - "name" [1]: -- 缺失 -- 错误,在 hapi v17.4.0 中启动服务器时
问题描述
我正在开发一个 hapi 应用程序,我想通过向用户发送电子邮件来实现忘记密码的逻辑。为此,我使用插件 hapi-mail 使用 AWS 的 SES 服务发送电子邮件。我收到一个错误:
"name" [1]: -- missing --
},
"options": {
"template": {
"engine": "handlebars",
"path": "./templates/"
},
"email": {
"engine": "ses",
"options": {
"region": "eu-west-1"
},
"defaultFrom": "abc@gmail.com"
}
}
}
[1] "name" is required
at new AssertionError (internal/errors.js:469:11)
at Object.exports.assert (/home/Utkarsh_Jaiswal/Documents/node-hapi-app/node-hapi-app/node_modules/hoek/lib/index.js:736:11)
at Object.exports.apply (/home/Utkarsh_Jaiswal/Documents/node-hapi-app/node-hapi-app/node_modules/hapi/lib/config.js:22:10)
at internals.Server.register (/home/Utkarsh_Jaiswal/Documents/node-hapi-app/node-hapi-app/node_modules/hapi/lib/server.js:392:31)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
(node:8069) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8069) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that arenot handled will terminate the Node.js process with a non-zero exit code.
这是定义选项并向服务器注册插件的代码片段:
const options = {
template: {
engine: 'handlebars',
path: './templates/'
},
email: {
engine: 'ses',
options: { accessKeyId: access_key, secretAccessKey: secret_key, region: 'eu-west-1' },
defaultFrom: 'abc@gmail.com'
}
};
await server.register([{
plugin: require('hapi-mail'),
options: options
}]);
如何解决此错误?还有更好的方法来实现这个想法。除了我正在使用的方法之外,应该用什么方法来处理这个问题?
解决方案
您尝试使用的插件适用于旧版本的 Hapi。它需要版本 15 由package.json
.
您正在使用的 Hapi 版本 17包含对插件注册方式的更改,这些更改与旧版本的 Hapi 不向后兼容。
您要么需要找到支持 Hapi 17 的其他邮件插件,要么需要降级以使用 Hapi 15,但我不推荐后者。
推荐阅读
- c++11 - C ++模板别名g ++ 5.4
- c - 自读取阻塞以来经过的时间
- logstash - 从 activemq 主题获取消息时,logstash 输入非常缓慢
- python - 每组时间戳之间的平均时间不按顺序
- r - 从R中的数据框中提取
- python - 使用 jupyter lab 重新连接到远程运行内核
- c# - 如何在运行时更改 WPF Material Design Palette?
- tensorflow.js - 加载 mobilenet v2 有效,但预训练的 mobilenet v2 失败
- ios - 无法使用 Xcode Instruments 定位内存泄漏
- performance - 如何按增长率顺序排列功能?所以 f(n) 是 O(g(n))