Problems running an Electron app with Reacjs

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


It looks like you’ve done a thorough job setting up your Dockerfile and project structure for running a React application within Electron on a Verdin iMX8 Mini module. However, the issue you’re facing seems to be related to the application freezing and not providing any logs or outputs.

Here are a few steps and suggestions to help you debug and resolve the issue:

  1. Check Electron Logs:
    Since the application is not providing any logs, you might want to add some logging to your Electron main process to see where it might be getting stuck. Modify your src/main.js to include more detailed logging:

    const { app, BrowserWindow } = require('electron');
    const path = require('path');
    const fs = require('fs');
    
    function createWindow() {
      console.log('Creating window...');
      const mainWindow = new BrowserWindow({
        width: 640,
        height: 480,
        webPreferences: {
          preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
        }
      });
    
      mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
    
      if (process.arch.includes("arm")) {
        mainWindow.setFullScreen(true);
      }
    
      mainWindow.webContents.openDevTools();
    
      mainWindow.webContents.on('did-finish-load', () => {
        console.log('Window finished loading');
      });
    
      mainWindow.on('closed', () => {
        console.log('Window closed');
      });
    }
    
    app.on('ready', () => {
      console.log('App is ready');
      createWindow();
    });
    
    app.on('window-all-closed', () => {
      if (process.platform !== 'darwin') {
        app.quit();
      }
    });
    
    app.on('activate', () => {
      if (BrowserWindow.getAllWindows().length === 0) {
        createWindow();
      }
    });
    
    process.on('uncaughtException', (error) => {
      console.error('Uncaught Exception:', error);
      fs.writeFileSync('/home/torizon/app/error.log', `Uncaught Exception: ${error.message}\n${error.stack}`);
    });
    

    This will help you see if the Electron app is starting correctly and where it might be failing.

  2. Check Docker Container Logs:
    Ensure that you are checking the correct logs. You can use the following command to see the logs of the running container:

    docker logs <container_id>
    

    Replace <container_id> with the actual container ID of your running container.

  3. Verify Dependencies:
    Ensure that all the necessary dependencies for running Electron and React are correctly installed in your Docker container. Sometimes missing dependencies can cause the application to freeze.

  4. Check for GPU Issues:
    Since you are using GPU acceleration, ensure that the GPU drivers and libraries are correctly installed and configured. You might want to try running the application without GPU acceleration to see if that resolves the issue. Modify the CMD in your Dockerfile to remove the GPU-related flags:

    CMD [ "./testui", "--no-sandbox", "--ozone-platform=wayland" ]
    
  5. Debugging Electron:
    You can also try running Electron in a more verbose mode to get more information. Modify your CMD in the Dockerfile to include the --enable-logging flag:

    CMD [ "./testui", "--no-sandbox", "--ozone-platform=wayland", "--enable-logging" ]
    
  6. Check Network and SSH Configuration:
    Ensure that the SSH configuration and network settings are correctly set up. Sometimes network issues can cause the application to hang.

  7. Simplify the Application:
    Try simplifying your application to the bare minimum and see if it runs. Gradually add back components to identify what might be causing the issue.

If none of these steps resolve the issue, you might need to provide more specific logs or error messages to further diagnose the problem.

Please, also check if these links can help you solve your problem:

Visual Studio Code IDE Extension | Toradex Developer Center.