异步引发SyntaxError:意外令牌( [英] Async throwing SyntaxError: Unexpected token (
本文介绍了异步引发SyntaxError:意外令牌(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用无头Chrome程序包进行测试木偶:
const puppeteer = require('puppeteer')
;(async() => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://google.com', {waitUntil: 'networkidle'})
// Type our query into the search bar
await page.type('puppeteer')
await page.click('input[type="submit"]')
// Wait for the results to show up
await page.waitForSelector('h3 a')
// Extract the results from the page
const links = await page.evaluate(() => {
const anchors = Array.from(document.querySelectorAll('h3 a'))
return anchors.map(anchor => anchor.textContent)
})
console.log(links.join('\n'))
browser.close()
})()
我将脚本运行为:node --harmony test/e2e/puppeteer/index.js
(v6.9.1)
但是我得到这个错误:
;(async() => {
^
SyntaxError: Unexpected token (
可能是什么问题?
注意:我正在使用Vue CLI的官方Webpack模板:
我发现:节点LTS(AKA节点6)目前不支持异步/等待机制.看 :有关详细信息,请参见此处: https://www. infoq.com/news/2017/02/node-76-async-await
I'm running a test using the headless Chrome package Puppeteer:
const puppeteer = require('puppeteer')
;(async() => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://google.com', {waitUntil: 'networkidle'})
// Type our query into the search bar
await page.type('puppeteer')
await page.click('input[type="submit"]')
// Wait for the results to show up
await page.waitForSelector('h3 a')
// Extract the results from the page
const links = await page.evaluate(() => {
const anchors = Array.from(document.querySelectorAll('h3 a'))
return anchors.map(anchor => anchor.textContent)
})
console.log(links.join('\n'))
browser.close()
})()
And I'm running the script as: node --harmony test/e2e/puppeteer/index.js
(v6.9.1)
But I get this error:
;(async() => {
^
SyntaxError: Unexpected token (
What could be the problem?
Note: I'm using Vue CLI's official Webpack template:
解决方案
I found out: node LTS (AKA node 6) is not supporting async / await mechanism right now. See :
See here for details : https://www.infoq.com/news/2017/02/node-76-async-await
这篇关于异步引发SyntaxError:意外令牌(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文