Backend process failing after packaging

I have the following code for an extension I built for Theia in the default-server.ts:

import { injectable } from 'inversify';
import { VisualiserService } from '../common/visualiser-protocol';
import * as cp from 'child_process';


@injectable()
export class VisualiserServiceImpl implements VisualiserService {

    async getEnvVariables(): Promise<Readonly<{ [key: string]: string | undefined }>> {
        return process.env;
    }

        /**
     * Remote procedure call for frontend. Visualises given model.
     * @param vis_path  Path of model on disk
     */
    async visualise(vis_path: string, options:any) {

        return this.visualiseFile(vis_path, options)
            .then((converted_path) => {
                return converted_path;
            });

    }


    protected async visualiseFile(vis_path: string, options:any): Promise<any> {

        const path = require('path');
        var visualiser = path.join(__dirname, '..', '..', 'src', 'visualiser', "visualiser.py");

        return new Promise((resolve, reject) => {
            var exec = cp.exec; 
            exec("netron " + visualiser, (error, stdout, stderr) => {
                if (error) {
                    console.log(`error: ${error.message}`);
                    resolve();
                }
                if (stderr) {
                    console.log(`stderr: ${stderr}`);
                    resolve();
                }
                console.log(`stdout: ${stdout}`);
                resolve();
            });
        })

    }

}

It is based off the same architecture as here for labelprovider except once it has detected a file of the desired file extension (.my for example), it executes a process (as you can see in the visualiseFile function). When built during development, this works like a charm. However, when I packaged the application with electron-builder, it fails.

Any advice on what might be causing this error or any ways to debug would be super useful. Thanks a lot!

It’s hard to know for sure without seeing the error, but this looks like a problem I once had with my electron build because electron-builder is trying to package everything into an asar archive and then my app was trying to fetch a resource that was in the archive instead of unpacked.

Check out the asarUnpack option in the electron builder configuration: https://www.electron.build/configuration/configuration.

You can also completely disable asar packaging by setting "asar": false in your build configuration.

For reference, here’s what Theia Electron’s electron builder configuration looks like: https://github.com/theia-ide/theia-apps/blob/master/theia-electron/electron-builder.yml

Worked like a charm! When I originally built using the electron-builder.yml, it said something along the lines of "highly recommend setting "asar":true", and so I did. Setting this to false solves the issue! Thanks a lot!