schickling/chromeless

SyntaxError: Unexpected identifier

Closed this issue · 7 comments

Hi,

I copy the example code into and example file named "test,js" and call it with this:

node test.js

and code


const chromeless = new Chromeless({ remote: true })

const screenshot = await chromeless
    .goto('https://www.graph.cool')
    .scrollTo(0, 2000)
    .screenshot()

console.log(screenshot)

await chromeless.end()

But it gives me this error:

♘ node test.js 
/Users/jameslynch/chromeless-test/test.js:3
const screenshot = await chromeless
                         ^^^^^^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

I am using node v8.9.3 on macos.

your code should be in an async function wrapper

async function run() {
// your code here
}

run().catch(console.error.bind(console))

Thanks @MaksJS, but the code already is in an async function wrapper.

As I above above I am using the sample code:

const { Chromeless } = require('chromeless')

async function run() {
  const chromeless = new Chromeless()

  const screenshot = await chromeless
    .goto('https://www.google.com')
    .type('chromeless', 'input[name="q"]')
    .press(13)
    .wait('#resultStats')
    .screenshot()

  console.log(screenshot) // prints local file path or S3 url

  await chromeless.end()
}

run().catch(console.error.bind(console))

and getting the errors.

Can I just run node test.js or do I need some special babel plugin?

no problem for me with node v8.9.3 and MacOS, also ok with v7.10.0

looks surprising since it doesn't recognize ES7 "await" syntax, you sure you're not using node v6.0 or lower ? maybe you haven't switch node version if you're using nvm check it with node -v

Thanks. As I said in the original post I'm using v8.9.3. Await is not yet included in ES7 so I would not expect it to recognize await.

I think you must have some special addition to your node installation that allows it to recognize async + await.

Although, it is working fine on my windows with node v8.9.3 :/