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

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

Leave a Comment