Seeking a way to initiate a background process in Electron's main process to handle heavy socket operations without interfering with the main process. Previously, this task was accomplished within a hidden window renderer.
Recent recommendations suggest using a child process spawned from the main process instead.
Struggling to implement this with TypeScript in the script file. Currently utilizing the Electron React boilerplate as the foundation for the application in its latest version.
Below is the code snippet used to execute the background script:
const electronProcess = UtilityProcess.fork('backgroundScript.ts', [
'ts-node',
'--esModuleInterop'
], {
detached: true,
stdio: 'ignore'
});
// Initiate the child process
electronProcess.start();
Upon execution, the code throws an error: "SyntaxError: Cannot use import statement outside a module."
The backgroundscript.ts file currently only contains a simple import statement for a dgram package.
In the code example, the attempt to set ts-node with the argument --esModuleInterop in order to enable module imports has been made, yet the issue persists.
Any assistance on this matter would be greatly appreciated.