title: In Node, how do I require files inside eval?
body: <p>I have two files <code>test.js</code> and <code>x.js</code>, in the same directory:</p>
  
  <ul>
  <li><p><code>test.js</code>:</p>
  
  <pre><code>console.log(eval( "require('x.js')" ));
  </code></pre></li>
  <li><p><code>x.js</code> is empty.</p></li>
  </ul>
  
  <p><strong>Expected</strong>: <code>require</code> returns <code>undefined</code>, so nothing is logged.</p>
  
  <p><strong>Actual</strong>: <code>node test.js</code> gives me <code>Error: Cannot find module 'x.js'</code> (stack-trace omitted for brevity).</p>
  
  <p>The situation sounds similar to <a href="https://stackoverflow.com/questions/12263104/why-is-context-inside-non-interactive-function-object-different-in-node-js">this other question</a>, with the differences that I've used <code>eval</code> rather than <code>new Function</code>, and <code>require</code> <em>is</em> defined, just working unexpectedly.</p>
  
  <hr>
  
  <p>Why is this?</p>
  
  <p>How do I correctly <code>require</code> a module in <code>eval</code>'d code?</p>