-
Notifications
You must be signed in to change notification settings - Fork 285
Description
I realize the Electron example itself is old and this library has been given a major overhaul recently. But I just wanted to get this on your radar.
The Electron example clearly envisions being able to require('node-pty') from a renderer process — something that an Electron app would have to opt into via nodeIntegration: true in the BrowserWindow constructor, but still easily doable.
But when you try to spawn a PTY on Windows, you're likely to receive this error:
Launching 'C:\WINDOWS\system32\cmd.exe' raised the following error: The V8 platform used by this instance of Node does not support creating Workers
This seems to be because of node-pty’s usage of worker_threads to spawn a worker in another thread. I don't claim to understand the root cause here, but Electron’s renderer process isn't really architecturally compatible with worker_threads.
This strategy has been in node-pty for at least five years, so this might've been affecting Electron users for at least that long as well.
As for workarounds: it's possible that useConpty: false is all you need to work around this! I haven't checked. For our purposes, we think we've managed to fix this by converting the worker_threads usage into a Web Worker.
Your response to this could be to change the Electron example, too, since Node integration in the renderer is off by default these days. Or it could be to recommend that people spawn a Node-only process from the renderer (via ELECTRON_RUN_AS_NODE=1) and consume node-pty from that process (which we've also been able to get working).
Or, if you really wanted bonus points, you'd abstract away the differences between worker implementations and have node-pty pick the best one after introspecting the runtime environment. But I wouldn't blame you if you didn't feel like doing that!