extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.1k stars 224 forks source link

Uncaught TypeError: (0 , util_1.promisify) is not a function #279

Open ipeglin opened 1 year ago

ipeglin commented 1 year ago

Describe the bug

Uncaught TypeError when importing PythonShell in TS linker file for running python script from Electron app. This also happens when using CommonJS with const PythonShell = require('python-shell').

Python code No relevant python code. Error happens at the moment of import

Javascript code import { PythonShell } from 'python-shell'; and const PythonShell = require('python-shell');

Expected behaviour No error. Allowing for creating python instance and running script in new process.

Actual behavior Error message displayed in console.

Uncaught TypeError: (0 , util_1.promisify) is not a function
    at node_modules/python-shell/index.js (index.ts:39)
    at __require (chunk-OL3AADLO.js?v=3f0bc4c7:9)
    at dep:python-shell:1

Other Information (please complete the following information):

Additional context Package.json:

{
    "name": "svelte-vite-electron",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
        "dev": "cross-env NODE_ENV=development elecrun --vite --preload preload.ts",
        "preview": "npm build && cross-env NODE_ENV=production electron ./app/",
        "build": "elecrun build --preload preload.ts && vite build",
        "clean": "elecrun clean",
        "pack": "npm run build && npm run rebuild && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -c ./electron-builder.yml --win --linux",
        "pack:all": "npm run build && npm run rebuild && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -c ./electron-builder.yml --win --linux --mac",
        "pack:win": "npm run build && npm run rebuild && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -c ./electron-builder.yml --win",
        "pack:mac": "npm run build && npm run rebuild && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -c ./electron-builder.yml --mac",
        "pack:linux": "npm run build && npm run rebuild && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -c ./electron-builder.yml --linux",
        "rebuild": "electron-rebuild -m ./app",
        "postinstall": "electron-builder install-app-deps",
        "prettier": "prettier -w ."
    },
    "devDependencies": {
        "@sveltejs/vite-plugin-svelte": "^1.0.0-next.10",
        "@types/node": "^15.14.9",
        "chalk": "^4.1.0",
        "cross-env": "^7.0.3",
        "electron": "^13.1.1",
        "electron-builder": "^23.6.0",
        "electron-rebuild": "^2.3.5",
        "electron-run": "^2.0.1",
        "esbuild": "^0.12.6",
        "prettier": "^2.3.0",
        "svelte": "^3.38.2",
        "svelte-preprocess": "^4.7.3",
        "ts-node": "^10.0.0",
        "tslib": "^2.2.0",
        "typescript": "^4.3.2",
        "vite": "^3.2.5"
    },
    "dependencies": {
        "fs-extra": "^10.0.0",
        "python-shell": "^3.0.1"
    }
}
uninstallit commented 1 year ago

Same issue here. I think the solution is this but the lib has to be updated.

const util = require('util');
require('util.promisify').shim(); 
Almenon commented 1 year ago

Theoretically you should not have to shim it unless you're using a old version of node I think. What version of node are you using @uninstallit ?

uninstallit commented 1 year ago

@Almenon I tried node v16, v18, and v20 . Open to suggestions.

I am using Vite 4.3.9 and using rollup-plugin-node-polyfills/polyfills to resolve node functions

egdenis commented 1 year ago

@uninstallit did you find a solution to this? Running into the same issue (node v19)

Almenon commented 1 year ago

That's really wierd, because according to the node docs util.promisify has been part of the official node API ever since v8.

See https://nodejs.org/docs/latest-v20.x/api/util.html#utilpromisifyoriginal

@uninstallit is your electron code open-source, by chance?