PhantomJS: “SyntaxError: Unexpected token =>”

倖福魔咒の 提交于 2019-12-10 13:33:50

问题


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).


回答1:


Phantomjs use ES5, not ES6 ;)

That's why it doesn't work as expected




回答2:


This failure can be eliminated by using phantom versions prior to 2.0.0. Notice that this is the phantom package and not the phantomjs package that is giving the failure.

if you want to use versions higher than 1.x. you will need to change your code from page.open(url, function(){}) to page.open(url).then(function(){}). this is explained very well at phantom npm site. Which gives detailed examples of how to do it



来源:https://stackoverflow.com/questions/40163150/phantomjs-syntaxerror-unexpected-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!