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?
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.com/ 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:
phantom
to the global variables box,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 complain this either.