Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to debug evaluated code? #98

Open
some1else opened this issue May 10, 2017 · 1 comment
Open

How to debug evaluated code? #98

some1else opened this issue May 10, 2017 · 1 comment

Comments

@some1else
Copy link

some1else commented May 10, 2017

The errors produced by the eval statement are incomprehensible to me.

I have a dozen or so safe document references in my code. However, one causes an error, and I can't pin point which one it is. The error I'm getting is:

ERROR in ReferenceError: document is not defined
    at Function.t.e (evalmachine.<anonymous>:1:812)
    at Object.getComponent (evalmachine.<anonymous>:1:25003)
    at n (evalmachine.<anonymous>:25:40385)
    at evalmachine.<anonymous>:25:40509
    at evalmachine.<anonymous>:25:19343
    at Array.forEach (native)
    at r (evalmachine.<anonymous>:25:19321)
    at r (evalmachine.<anonymous>:25:40483)
    at n (evalmachine.<anonymous>:25:38302)
    at u (evalmachine.<anonymous>:25:35271)

Unfortunately, those line and character numbers don't even line up with the compiled main.js file.

I had no luck with node --inspect and vm.runInNewContext/vm.runInThisContext.

What is the intended way of debugging this?

@nuclearpidgeon
Copy link

I had this problem recently - the way I got around it was by:

  1. writing a separate script file that imports/requires the static site rendering bundle and calls the exported render() function manually
  2. running this separate script file directly with node --inspect or the VSCode debugger (I had to tweak the source map options in Webpack to get useful stack traces out of VSCode though)

You'll get the same stack trace that the eval() produces, but in a proper debugger UI with sourcemaps :)

For reference, here's the guts of the script I ended up writing:

var staticSite = require('./.tmp/webpack/staticSite.bundle.js');
var staticSiteRenderer =  staticSite.default;
staticSiteRenderer({path: '/'}, function(renderedHtml) {
  console.log("Finished rendering root path!")
  console.log("Output is: " + renderedHtml.length.toString() + " characters long")
  // console.log(renderedHtml)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants