gpt4 book ai didi

phantomjs - 从 phantomjs "SyntaxError: Parse error"消息获取更多信息

转载 作者:行者123 更新时间:2023-12-03 05:56:08 25 4
gpt4 key购买 nike

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

phantomjs file.js
SyntaxError: Parse error

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

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

有没有更好的方法来获取至少一个行号?或者有任何提示吗?

最佳答案

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

如果文件有效,那么 node 也会尝试运行它,如果您的脚本依赖于 node 环境中不可用的内容,则运行将会失败。因此您必须忽略任何运行时错误。

例如,给定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 - 从 phantomjs "SyntaxError: Parse error"消息获取更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14905664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com