Just because this is the top answer on Google at the moment, I figured I’d add a solution for a case I just ran across:
I had this issue using express with ejs templates – the issue was that I failed to close an ejs block, and the file was js code – something like this:
var url="<%=getUrl("/some/url")"
/* lots more javascript that ejs tries to parse in memory apparently */
This is obviously a super specific case, OP’s solution should be used the majority of the time. However, OP’s solution would not work for this (ejs stack trace won’t be surfaced by ofe).