title: Javascript throws 'ReferenceError: require is not defined'
body: <p>I am running a piece of Javascript code inside my Python code using the <code>js2py</code> library.It works fine for all kinds of Javascript code thrown at it and processes the result.However I am encountering an error when a <strong>'require'</strong> keyword is used in the Javascript code.Here is my code below</p>
  
  <pre><code>import js2py
  
  data = '''var jsonata = require('jsonata');
  
  var data = {
    example: [
      {value: 4},
      {value: 7},
      {value: 13}
    ]
  };
  var expression = jsonata("$sum(example.value)");
  var result = expression.evaluate(data);
  console.log(result);
  '''
  
  data = js2py.eval_js(data)
  print(data)
  </code></pre>
  
  <p>Here <strong>jsonata</strong> is a javascript library for parsing JSON installed through npm.</p>
  
  <p>Below is the error I receive</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/souvik/PycharmProjects/ServiceHandler/Testjs.py", line 67, in &lt;module&gt;
      data = js2py.eval_js(data)
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 113, in eval_js
      return e.eval(js)
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 182, in eval
      self.execute(code, use_compilation_plan=use_compilation_plan)
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 177, in execute
      exec(compiled, self._context)
    File "&lt;EvalJS snippet&gt;", line 2, in &lt;module&gt;
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 899, in __call__
      return self.call(self.GlobalObject, args)
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 1344, in call
      return Js(self.code(*args))
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/host/jseval.py", line 42, in Eval
      executor(py_code)
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/host/jseval.py", line 49, in executor
      exec(code, globals())
    File "&lt;string&gt;", line 2, in &lt;module&gt;
    File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 1079, in get
      raise MakeError('ReferenceError', '%s is not defined' % prop)
  js2py.internals.simplex.JsException: ReferenceError: require is not defined
  </code></pre>
  
  <p>However when I put just the javascript code in a file and run it from the command line, it works.</p>
  
  <p><strong>jstest.js</strong></p>
  
  <pre><code>var jsonata = require("jsonata");
  
  var data = {
    example: [
      {value: 4},
      {value: 7},
      {value: 13}
    ]
  };
  var expression = jsonata("$sum(example.value)");
  var result = expression.evaluate(data); 
  console.log(result)
  </code></pre>
  
  <p>In the command line</p>
  
  <pre><code>node jstest.js  --&gt; gives 25
  </code></pre>
  
  <p>Now I did some investigation on the error and it turns out that <strong>'require'</strong> is a browser requirement and is not for <code>node.js</code>. It also turns out there is an alternative for this called <code>require.js</code> that fixes this problem.So I went to their documentation but couldn't make much sense of how I could define <strong>require</strong> in my Javascript code.Also I pass jsonata as an argument to <strong>require</strong> which is a <strong>.js</strong> file.How do I use <code>require.js</code> framework to handle a jsonata.js file as opposed to function declaration given in the examples?I may be wrong in my understanding of the subject but I need to get a clarification on this?Is there any way I can make this work?</p>
  
  <p>Note: I am running the code in the server side.</p>