PhantomJS: "SyntaxError: Unexpected token =>"

时间:2016-10-20 19:41:28

标签: phantomjs

Im currently having problems using phantomJS. Any suggestions?

acanyon$ babel-node source_parser.js http://url

/Users/.../node/node_modules/phantom/lib/index.js:23
  return new Promise(resolve => resolve(new _phantom2.default(args, config)));
                             ^^
SyntaxError: Unexpected token =>
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Module._extensions..js (module.js:478:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/acanyon/.nvm/versions/node/v0.12.4/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/acanyon/fashionblog/node/source_parser.js:4:15)
    at Module._compile (module.js:460:26)

Am I missing a shim for es6? (the remainder of the script is written in es5).

2 个答案:

答案 0 :(得分:5)

Phantomjs use ES5, not ES6 ;)

That's why it doesn't work as expected

答案 1 :(得分:0)

使用2.0.0之前的幻像版本可以消除此故障。 请注意,这是幻像包,而不是给出失败的phantomjs包。

如果您想使用高于1.x的版本。您需要将代码从page.open(url,function(){})更改为page.open(url).then(function(){})。 这在phantom npm网站上得到了很好的解释。其中提供了如何操作的详细示例