Running @hapi/hapi giving error "#meetings = null SyntaxError: Invalid or unexpected token"

Running @hapi/hapi giving error "#meetings = null SyntaxError: Invalid or unexpected token"

正在使用

@hapi/hapi : ^20.0.0

node.js : v10.19.0

得到以下错误堆栈

|     #meetings = null;
|     ^
| 
| SyntaxError: Invalid or unexpected token
|     at Module._compile (internal/modules/cjs/loader.js:723:23)
|     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
|     at Module.load (internal/modules/cjs/loader.js:653:32)
|     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
|     at Function.Module._load (internal/modules/cjs/loader.js:585:3)

正在使用以下代码

'use strict';

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

const init = async () => {

    const server = Hapi.server({
        port: 5000,
        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();

已将节点版本从 v10.19.0 升级到 v12.18.3,并且有效

参考来自https://github.com/outmoded/sntp/issues/37

您应该将 Node 版本升级到支持 private class fields 的 12+,例如 #meetings


参考文献: Table of Compatibility