无法启动使用 hapi.js 编写的基本服务器

Cannot up the basic sever written with hapi.js

今天,我决定使用 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\_logs20-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();

那个代码对我有用。

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

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