从phantomjs获得更多信息"SyntaxError:解析错误";信息 [英] getting more information from phantomjs "SyntaxError: Parse error" message

查看:170
本文介绍了从phantomjs获得更多信息"SyntaxError:解析错误";信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的脚本,不是我写的.当我运行它时,我得到:

I have a long script that was not written by me. When i run it I get:

phantomjs file.js
SyntaxError: Parse error

我查看了手册和--help,而我能想到的最好的方法是:

i checked out the manual and --help, and the best i could came up with was:

phantomjs --debug=yes file.js
(irrelevant debug statement from CookieJar)
SyntaxError: Parse error

是否有更好的方法来获取至少一个行号?还是有任何提示?

Is there any better way to get at least a line number? or any hint at all?

推荐答案

使用 node 运行文件.如果存在解析错误,它将报告该错误.

Run the file with node. If there is a parse error it will report it.

如果文件有效,那么 node 也会尝试运行该文件,如果您的脚本依赖于 node 环境中不可用的内容,则该操作将失败.因此,您将不得不忽略所有运行时错误.

If the file is valid, then node will also try to run it, which will fail if your script depends on something not available in your node environment. So you'll have to ignore any runtime errors.

例如,给定 hello-world.js:

// Say Hello World twice
for (var i=0; i<2; i++) {
  console.log("Hello World") );
}

节点上运行它:

node hello-world.js

输出:

/home/someone/somewhere/hello-world.js:3
  console.log("Hello World") );
                             ^
SyntaxError: Unexpected token )
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

这篇关于从phantomjs获得更多信息"SyntaxError:解析错误";信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆