最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - (Node J.S.) SyntaxError: Unexpected token function on an async function - Stack Overflow

programmeradmin2浏览0评论

So I'm trying to use async/await but i get this error:

async function something(options) {
  ^^^^^^^^
SyntaxError: Unexpected token function

Here's the code:

var request = require('superagent');

async function something(options) {
    let response = await request.get("apiurlblabla");
    if(response) {
      .query(({'queryqeureur}))
      .query(({'uqeryqery'}))
      var jsonString = JSON.parse(res.text)
      console.log(jsonString.propertyblabla);
      console.log(jsonString.propertyblabla)
    }
}

So I'm trying to use async/await but i get this error:

async function something(options) {
  ^^^^^^^^
SyntaxError: Unexpected token function

Here's the code:

var request = require('superagent');

async function something(options) {
    let response = await request.get("apiurlblabla");
    if(response) {
      .query(({'queryqeureur}))
      .query(({'uqeryqery'}))
      var jsonString = JSON.parse(res.text)
      console.log(jsonString.propertyblabla);
      console.log(jsonString.propertyblabla)
    }
}
Share Improve this question edited May 6, 2018 at 18:28 SpecialVirusTasker asked Jul 23, 2017 at 17:05 SpecialVirusTaskerSpecialVirusTasker 553 silver badges12 bronze badges 5
  • 1 Is your node up to date? Async/await got enabled in node 7 I think. – Sirko Commented Jul 23, 2017 at 17:07
  • oh shit bro im on 6.10 – SpecialVirusTasker Commented Jul 23, 2017 at 17:08
  • You still have syntax errors on top of having a wrong version. – Darkrum Commented Jul 23, 2017 at 18:49
  • and what are the errors? – SpecialVirusTasker Commented Aug 5, 2017 at 23:51
  • see also stackoverflow./q/37815790/2969544 – oklas Commented Oct 21, 2017 at 21:43
Add a ment  | 

2 Answers 2

Reset to default 7

async function is supported officially in nodejs 8 and later. you should update your nodejs version to 8 or later.

Install node version manager:

curl -o- https://raw.githubusercontent./creationix/nvm/v0.33.6/install.sh | bash

Install new version of node:

nvm install 8.0

Update verion which uses:

nvm use 8.0
发布评论

评论列表(0)

  1. 暂无评论