javascript - Getting more information from “SyntaxError: Parse error” message in PhantomJSCasperJS - Stack Overflow

I have a long CasperJS script. When I run it I get:phantomjs file.jsSyntaxError: Parse errorIs the

I have a long CasperJS script. When I run it I get:

phantomjs file.js    
SyntaxError: Parse error

Is there a way to get some more information about the error. At least a line number? or any hint at all?

I have a long CasperJS script. When I run it I get:

phantomjs file.js    
SyntaxError: Parse error

Is there a way to get some more information about the error. At least a line number? or any hint at all?

Share Improve this question edited Jan 27, 2015 at 11:28 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked Jan 27, 2015 at 7:36 Anuj GuptaAnuj Gupta 6,5728 gold badges39 silver badges56 bronze badges 1
  • Possible duplicate of getting more information from phantomjs "SyntaxError: Parse error" message – bob esponja Commented Apr 22, 2016 at 10:31
Add a ment  | 

3 Answers 3

Reset to default 5

Try run the file.js with node, so for your example:

node file.js

It's not possible to determine this in PhantomJS itself. The documentation on phantom.onError says:

This is the closest it gets to having a global error handler in PhantomJS

And this doesn't catch the syntax error. If you try to run it with the --debug=true option, you will see a lot of debug messages, but the final error has still the same amount of information.

Another thing that I tried was to use a second PhantomJS script which reads the original script and tries to eval it. The phantom.onError event is triggered in this case, but the trace argument is empty.

The good thing is that PhantomJS/CasperJS scripts are just JavaScript, so you can paste them to http://jslint./ or run a dedicated jslinter on them to see where the problem lies. There are some options that you have to mark on the site or otherwise you will get a lot of errors:

  • add phantom to the global variables box,
  • enable node.js mode and
  • tolerate "everything" (or those things that you actually want to tolerate)

I spent a whole 8hrs on this to find a trick for this problem. The trick is to run "phantomjs" and type 'require "path_to_js_file"'. I used 2.1.1 version of phantomjs. Likely 2.2 also works.

Then there will be a stack trace that shows which line is the offender. You won't see this in testem output.

In my case, if you define a property twice for an object, it will work for chrome, firefox etc, but not phantomjs. Lint might help but there are >5K lint errors for the project I work on and it is practically impossible to see what's wrong. Also the particular problem is likely hidden under the same bucket of "javascript strict mode violation". Nodejs didn't plain this either.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745295110a4621091.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信