首页 > 解决方案 > 尝试从 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.jsvue.jsnpm-install

解决方案


您在评论中说您的 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"
},

推荐阅读