【问题标题】:Cannot up the basic sever written with hapi.js无法启动用 hapi.js 编写的基本服务器
【发布时间】:2020-04-14 20:24:10
【问题描述】:

今天,我决定使用 node.js 框架之一 hapi.js。我遵循了他们的getting started 指南,安装了hapi,并将启动基本服务器所需的代码放入index.js 中,并将npm start 设置为node index.js。完成所有这些操作后,当我尝试使用npm start 运行服务器时,我收到以下错误。:-(。非常感谢任何帮助克服这个问题。

F:\app-Backend\node_modules\@hapi\hapi\lib\core.js:51
   actives = new WeakMap();                                                   // Active requests being processed
            ^
SyntaxError: Unexpected token =
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app-backend@1.0.0 start: `node ./index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app-backend@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Pavindu\AppData\Roaming\npm-cache\_logs\2020-04-13T08_45_49_367Z-debug.log

index.js

const Hapi = require('@hapi/hapi');

const init = async () => {

    const server = Hapi.server({
        port: 8080,
        host: 'localhost'
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {

    console.log(err);
    process.exit(1);
});

init();

【问题讨论】:

    标签: node.js hapijs


    【解决方案1】:

    该代码对我有用。

    你还记得npm install @hapi/hapi --save吗?

    所以这是因为最新版本的 hapi 只能在节点 12+ 上运行

    【讨论】:

    • 是的,我有,但我仍然无法让它工作..:- (。我不明白为什么 hapi 会出现这个错误。我可以运行 express.js 应用程序我的电脑没有任何问题..
    • 我可以确认:代码也适用于我(node -v v13.2.0npm -v 6.14.4@hapi/hapi: ^19.1.1)
    • the latest version of hapi will only work on node 12+
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 2019-07-20
    相关资源
    最近更新 更多