getting more information from phantomjs “SyntaxError: Parse error” message

前端 未结 7 2207
感动是毒
感动是毒 2020-12-03 04:38

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

phantomjs file.js
SyntaxError: Parse error

i checked out the manual a

7条回答
  •  春和景丽
    2020-12-03 04:44

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

    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.

    For example, given hello-world.js:

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

    Run it with node:

    node hello-world.js
    

    Output:

    /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
    

提交回复
热议问题