PythonMonkey icon indicating copy to clipboard operation
PythonMonkey copied to clipboard

require not definied.

Open lkodotsrv opened this issue 1 year ago • 0 comments

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Windows 10

Python version (python --version)

3.12.7

PythonMonkey version (pip show pythonmonkey)

1.1.0

Bug Description

When I require a module from a JS file or evaluation it will raise a ReferenceError

Standalone code to reproduce the issue

import pythonmonkey as pmjs
import os

def main() -> None:
    with open(os.path.join(os.getcwd(), 'myModule.js'), 'w') as f: f.write('function sqrt($){function r($){return $<0?-$:$}if($<0)return -1;let t=$/2,n;for(;!(1e-7>r((n=(t+$/t)/2)-t));)t=n;return n}exports.sqrt=sqrt;'); f.close() # JavaScript simple SQRT function
    pmjs.eval('''
const { sqrt } = require('./sqrt');
console.log(sqrt(230));
''')
    return 0
    
if __name__ == '__main__': main()

Relevant log output or backtrace

PS C:\Users\aleix\Desktop\Redleach> & C:/Users/aleix/AppData/Local/Programs/Python/Python312/python.exe c:/Users/aleix/Desktop/Redleach/test.py
Traceback (most recent call last):
  File "c:\Users\aleix\Desktop\Redleach\test.py", line 12, in <module>       
    if __name__ == '__main__': main()
                               ^^^^^^
  File "c:\Users\aleix\Desktop\Redleach\test.py", line 6, in main
    pmjs.eval('''
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 2, column 18:
ReferenceError: require is not defined
Stack Trace:
  @evaluate:2:18

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

lkodotsrv avatar Dec 11 '24 20:12 lkodotsrv