2017-09-06 68 views
2

我使用的是无头镀铬包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() 
})() 

而且我运行该脚本为:node --harmony test/e2e/puppeteer/index.js(v6.9.1)

但我得到这个错误:

;(async() => { 
    ^
SyntaxError: Unexpected token (

可能是什么问题

注:我使用Vue的CLI官方的WebPack模板:

+0

您可能会发现http://node.green/有用。 –

回答

1

我想你的代码,我的笔记本电脑棉绒之后它完美地工作: enter image description here

也许你有一个环境的问题。

你有没有考虑在行首去掉分号? 它看起来不正确的编程。或者也许是一个webpack的问题。

+0

您正在使用哪个版本的节点? – alex

+1

我正在使用最新版本,当前是8.4.0 –