Skip to content

Lacking Support for Node.js 'process' Variable #267

Open
@arvindavoudi

Description

@arvindavoudi

🚨 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

  1. Install pythonmonkey using the command pip install pythonmonkey.
  2. Create a project directory with the following structure:
my_project/
├── main.py
└── package.json
  1. Add the following contents to my_project/package.json:
{
    "dependencies": {
        "react": "^18.2.0",
        "react-dom": "^18.2.0"
    }
}
  1. Run npm install in the project directory to install the Node.js dependencies listed in my_project/package.json, specifically 'react' and 'react-dom'.

  2. Add the following Python code to my_project/main.py directory to use the "react-dom/server" module:

import pythonmonkey as pm
reactdom_server = pm.require('./node_modules/react-dom/server')
  1. Finally execute my_project/main.py using the command python3 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions