node.js - 尝试从 git hub node.js 版本 v6.10.0 安装 MERN-Social-Network
问题描述
我试图从Faiyaz Shaikh yTakkar 的 git hub node js 代码安装 MERN-Social-Network
并面对这个错误:
www@www-PC MINGW64 /d/Vue-Mini-Social-Network-master
$ npm start
> vue-mini-social-network@1.0.0 start D:\Vue-Mini-Social-Network-master
> nodemon app.js
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
D:\Vue-Mini-Social-Network-master\routes\user-routes.js:25
app.post('/user/signup', async (req, res) => {
^
SyntaxError: Unexpected token (
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Vue-Mini-Social-Network-master\app.js:19:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
[nodemon] app crashed - waiting for file changes before starting...
解决方案
您在评论中说您的 Node.JS 版本v6.10.0
不幸的是这个版本不支持async/await
功能。
你可以在这里查看:https ://node.green/#ES2017-features-async-functions
Async/await
支持从7.0.0
您需要添加--harmony
标志以启用 ES6/ES7 功能的版本开始。从中7.6.0
得到支持。
因此,有多种方法可以实现相同的结果。
1) 使用Promise
而不是async/await
2) 用于babel
将代码转译成 ES5。babel-load
如果您使用的是 webpack(主要用于前端产品),您可以通过运行代码来做到这一点
3)您可以将节点更新为>7.6.x
注意:如果您在该package.json
存储库中看到,您可以看到建议在此项目中使用 node>8 (根据作者)
"engines": {
"node": ">= 8.0.0"
},
推荐阅读
- sql - 根据分组重新编号值列表
- javascript - 打字稿默认函数参数
- javascript - Django 完整日历
- android - Flutter - 如何根据手机的语言更改应用程序的名称
- r - 在 R 中,我如何解释 glmnet 包中的图形?
- python - Pandas - 使用 groupby 将列与字符串组合 - TypeError 消息的问题
- c++ - 无法找出多个身份不明的参考资料::
- python-3.x - 如何检查/取消 Azure 存储容器删除操作
- java - 在类路径中覆盖 mssql-jdbc 驱动程序时如何解决错误 - 在类中找不到主方法
- r - 候选 SNP 主成分的判别分析