无效的寄存器选项"值"必须是nodejs中的对象

时间:2018-01-31 09:03:05

标签: node.js hapijs

当我尝试运行我的nodejs应用时,我收到以下unhandled rejection错误:

(node:8645) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Invalid register options "value" must be an object
    at Object.exports.apply (/home/igniva-js-vaibhav/Official/project/testProject/node_modules/hapi/lib/config.js:22:10)
    at internals.Server.register (/home/igniva-js-vaibhav/Official/project/testProject/node_modules/hapi/lib/server.js:352:26)
    at Object.<anonymous> (/home/igniva-js-vaibhav/Official/project/testProject/index.js:44:8)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
(node:8645) 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:8645) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2 个答案:

答案 0 :(得分:0)

我认为那是直截了当的。我假设你正在启动服务器?传递给它的值必须是对象。 Hapi需要一个对象来配置服务器。任何其他值都会抛出错误

  

const server = Hapi.server({load:{sampleInterval:1000}});

来自他们的文档,Hapi Api

答案 1 :(得分:0)

您可能已经解决了这个问题,但是... 由于无效注册,我遇到了同样的问题:

server.register(
        require('hapi-auth-cookie'**)**, (er) => { });

在HapiJS中正确的依赖项注册是:

server.register(
        require('hapi-auth-cookie', (er) => { }));