-
Notifications
You must be signed in to change notification settings - Fork 42
Description
🚨 Problem with Node Modules Requiring Process Identification
📝 Description
The "process" variable is fundamental in Node.js environments, suggesting that pythonmonkey might not fully emulate or provide a Node.js-like environment for certain modules. Understanding how to properly bridge this gap or if there's a workaround would be crucial for progressing with my project.
🔄 Steps to Reproduce
- Install
pythonmonkeyusing the commandpip install pythonmonkey. - Create a project directory with the following structure:
my_project/
├── main.py
└── package.json
- Add the following contents to
my_project/package.json:
{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}-
Run
npm installin the project directory to install the Node.js dependencies listed inmy_project/package.json, specifically 'react' and 'react-dom'. -
Add the following Python code to
my_project/main.pydirectory to use the "react-dom/server" module:
import pythonmonkey as pm
reactdom_server = pm.require('./node_modules/react-dom/server')- Finally execute
my_project/main.pyusing the commandpython3 main.py.
🌟 Expected Behavior
I expected to successfully import and use "react-dom/server" in my Python script for server-side rendering of React components, leveraging pythonmonkey for integration.
🛑 Actual Behavior
Encountering an error when executing my_project/main.py, indicating a problem with recognizing the process variable, which is essential for some Node.js modules:
Traceback (most recent call last):
File "/my_project/main.py", line 2, in <module>
reactdom_server = pm.require('./node_modules/react-dom/server')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pythonmonkey/require.py", line 353, in require
return createRequire(filename)(moduleIdentifier)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 4:
ReferenceError: process is not definedℹ️ Additional Information
PythonMonkey Installation Method:
Installed from pip
OS Platform and Distribution:
MacOS 14.2.1
Python Version (python --version):
3.11.7
PythonMonkey Version (pip show pythonmonkey):
0.3.0
Metadata
Metadata
Assignees
Labels
Type
Projects
Status