node.js - 无法启动用 hapi.js 编写的基本服务器
问题描述
今天,我决定使用 node.js 框架之一,hapi.js。我按照他们的入门指南,安装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();
解决方案
该代码对我有用。
你记得npm install @hapi/hapi --save
吗?
所以这是因为最新版本的 hapi 只能在节点 12+ 上运行
推荐阅读
- apache - 在 ubuntu 服务器 16.04 上部署 php 应用程序
- visual-studio - dotnet Cli 尝试生成代码覆盖率统计信息时出错
- sublimetext3 - 如何使用类似 VIM 的“yX”键盘组合在 Sublime 文本中拉到剪贴板
- java - 为什么我在 java 中使用 arraylist 得到覆盖输出?
- google-bigquery - 推断 BigQuery 表加载的 avro 架构
- python - 使用分类色调可视化仅 2 个变量的散点图
- python - scipy.optimize.minimize 太慢了。我怎样才能加快速度
- python - 基于索引的python列表中的优雅切片
- c# - 创建运行时模拟:使用 Expression.Throw 编译 Expression.Throw 后的 InvalidProgramException
- python - 在lookahead和lookbehind之间选择部分