SyntaxError showing token not in the inputΒ #6427
Copy link
Copy link
Closed
Labels
v8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
Description
- Version: v6.0.0
- Platform: Mac OS X 10.11.4
Givenfoo.js just containing the following:
++When I run node foo.js, I get:
/private/tmp/foo.js:3
});
^
SyntaxError: Unexpected token }
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:511:25)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:159:18)
at node.js:444:3
But the token } does not appear in foo.js. This could be related to #3411, not sure. When I run with just v8, I get an appropriate error:
/tmp/foo.js:1: SyntaxError: Unexpected end of input
++
^^
SyntaxError: Unexpected end of input
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
v8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
Activity
cjihrig commentedon Apr 27, 2016
I think this is expected due to Node wrapping your code.
mscdex commentedon Apr 27, 2016
Yes, the reason it does not point to your
++line is because the parser is expecting a variable afterwards somewhere (even on a following line). So it instead sees}from the node module wrapper function which is not a valid variable name token and exits. You can verify this is the case with:msridhar commentedon Apr 27, 2016
To be clear, this is not a serious bug for me; I just wanted to report it in case it was indicative of some more important problem. Is this whole "node module wrapper function" behavior documented somewhere? It seems unfortunate that it can lead to such a confusing SyntaxError. But, it might not be worth it to fix this one.
cjihrig commentedon Apr 27, 2016
I'm not sure if it's actually documented. Interestingly enough, the docs do say:
Where "as though" could be interpreted as "because" :-)
mtharrison commentedon Apr 27, 2016
Doesn't seem to be documented anywhere. Might be useful to include so I made a PR: #6433
stevemao commentedon Apr 27, 2016
I feel user shouldn't know about this. At least the error shouldn't point to the internally code
});.cjihrig commentedon Jun 16, 2016
This was closed a while back in 7164003.
doc: mention existence/purpose of module wrapper