【发布时间】: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();
【问题讨论】: