'Getting PythonShell to Work with Electron

I am trying to get a basic python code to work with electron-forge.

On the Node JS and python-shell websites, they want you to do this. But it will not let me because it will not let me use require() function because it is not defined. (I also tried doing this after removing type:module from my json file.)

let {PythonShell} = require('python-shell')

So people are saying to do this...

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

But now I am stuck in a loop because I cannot import that because it is outside of a module.

import{PythonShell} from 'python-shell'

This also does not work.

This is my package json file.

   "name": "my-new-app",
  "productName": "my-new-app",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": "src/index.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "type": "module",
    "lint": "echo \"No linting configured\""
  },
  "keywords": [],
  "author": "dylan",
  "license": "MIT",
  "config": {
    "forge": {
      "packagerConfig": {},
      "makers": [
        {
          "name": "@electron-forge/maker-squirrel",
          "config": {
            "name": "my_new_app"
          }
        },
        {
          "name": "@electron-forge/maker-zip",
          "platforms": [
            "darwin"
          ]
        },
        {
          "name": "@electron-forge/maker-deb",
          "config": {}
        },
        {
          "name": "@electron-forge/maker-rpm",
          "config": {}
        }
      ]
    }
  },
  "dependencies": {
    "electron-reload": "^2.0.0-alpha.1",
    "electron-squirrel-startup": "^1.0.0",
    "esm": "^3.2.25",
    "python-shell": "^3.0.1"
  },
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.63",
    "@electron-forge/maker-deb": "^6.0.0-beta.63",
    "@electron-forge/maker-rpm": "^6.0.0-beta.63",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.63",
    "@electron-forge/maker-zip": "^6.0.0-beta.63",
    "electron": "18.1.0"
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source