admin管理员组

文章数量:1195187

Getting blank screen in windows after electron-builder react electron app.

Here is package.json. Getting blank screen in windows after electron-builder react electron app.

      {
  "name": "SmallBusinessManagement",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.5.3",
    "cross-env": "^7.0.2",
    "date-fns": "^2.16.1",
    "electron-is-dev": "^1.2.0",
    "jquery": "^3.5.1",
    "jspdf": "^2.1.1",
    "jspdf-autotable": "^3.5.13",
    "knex": "^0.21.12",
    "moment": "^2.29.1",
    "popper.js": "^1.16.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-popper": "^2.2.4",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "sqlite3": "^5.0.0",
    "wait-on": "^5.2.0",
    "web-vitals": "^0.2.4"
    
  },
  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "dist": "electron-builder",
    "pack": "electron-builder --dir",
    "react-start": "react-scripts start",
    "react-build": "react-scripts build",
    "react-test": "react-scripts test",
    "react-eject": "react-scripts eject",
    "electron-build": "electron-builder",
    "release": "yarn react-build && electron-builder --publish=always",
    "start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\""
  },
  "build": {
    "productName":"SmallBussinessManagement",
    "appId": "com.smallbusinessmanagement",
    "dmg": {
      "contents": [
        {
          "x": 110,
          "y": 150
        },
        {
          "x": 240,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "win": {
      "target": "NSIS",
      "icon": "build/icon.ico"
    },
    "directories": {
      "buildResources": "resources",
      "output": "release"
  }
  },

  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "description": "Small business management is used to manage daily sell and buy.",
  "author": "rakshithgowda KV",
  "main": "public/electron.js",
  "homepage": "./addItem",
  "devDependencies": {
    "electron": "latest",
    "electron-builder": "latest"
  },
  "files": [
    "*.js",
    "build",
    "node_modules"
  ]
}

public/electron.js. Do i need to isntall any dependency ?

const { app, BrowserWindow,Menu } = require('electron')
require('../src/messgaeController/main');
const path = require("path");
const isDev = require("electron-is-dev");

let addItem ;
let win;
function createWindow () {
   win = new BrowserWindow({
    width: 800,
    height: 600,
    icon:"build/icon.ico",
    webPreferences: {
      nodeIntegration: true,
      // webSecurity: false
    }
  })

  win.loadURL(isDev? "http://localhost:3000": `file://${__dirname}/../build/index.html`);
    win.on("closed", () => (mainWindow = null));

  const mainMenu = Menu.buildFromTemplate(menuTemplate);
  Menu.setApplicationMenu(mainMenu);
  // win.webContents.openDevTools()

  win.on("close",()=>app.quit())
}

Not sure why it's showing blank page after build. Tried different approach, didn't work

enter image description here

Getting blank screen in windows after electron-builder react electron app.

Here is package.json. Getting blank screen in windows after electron-builder react electron app.

      {
  "name": "SmallBusinessManagement",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.5.3",
    "cross-env": "^7.0.2",
    "date-fns": "^2.16.1",
    "electron-is-dev": "^1.2.0",
    "jquery": "^3.5.1",
    "jspdf": "^2.1.1",
    "jspdf-autotable": "^3.5.13",
    "knex": "^0.21.12",
    "moment": "^2.29.1",
    "popper.js": "^1.16.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-popper": "^2.2.4",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "sqlite3": "^5.0.0",
    "wait-on": "^5.2.0",
    "web-vitals": "^0.2.4"
    
  },
  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "dist": "electron-builder",
    "pack": "electron-builder --dir",
    "react-start": "react-scripts start",
    "react-build": "react-scripts build",
    "react-test": "react-scripts test",
    "react-eject": "react-scripts eject",
    "electron-build": "electron-builder",
    "release": "yarn react-build && electron-builder --publish=always",
    "start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\""
  },
  "build": {
    "productName":"SmallBussinessManagement",
    "appId": "com.smallbusinessmanagement",
    "dmg": {
      "contents": [
        {
          "x": 110,
          "y": 150
        },
        {
          "x": 240,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "win": {
      "target": "NSIS",
      "icon": "build/icon.ico"
    },
    "directories": {
      "buildResources": "resources",
      "output": "release"
  }
  },

  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "description": "Small business management is used to manage daily sell and buy.",
  "author": "rakshithgowda KV",
  "main": "public/electron.js",
  "homepage": "./addItem",
  "devDependencies": {
    "electron": "latest",
    "electron-builder": "latest"
  },
  "files": [
    "*.js",
    "build",
    "node_modules"
  ]
}

public/electron.js. Do i need to isntall any dependency ?

const { app, BrowserWindow,Menu } = require('electron')
require('../src/messgaeController/main');
const path = require("path");
const isDev = require("electron-is-dev");

let addItem ;
let win;
function createWindow () {
   win = new BrowserWindow({
    width: 800,
    height: 600,
    icon:"build/icon.ico",
    webPreferences: {
      nodeIntegration: true,
      // webSecurity: false
    }
  })

  win.loadURL(isDev? "http://localhost:3000": `file://${__dirname}/../build/index.html`);
    win.on("closed", () => (mainWindow = null));

  const mainMenu = Menu.buildFromTemplate(menuTemplate);
  Menu.setApplicationMenu(mainMenu);
  // win.webContents.openDevTools()

  win.on("close",()=>app.quit())
}

Not sure why it's showing blank page after build. Tried different approach, didn't work

enter image description here

Share Improve this question edited Feb 14, 2021 at 22:25 RAKSHITHGOWDA K V asked Feb 14, 2021 at 21:40 RAKSHITHGOWDA K VRAKSHITHGOWDA K V 811 gold badge1 silver badge5 bronze badges 3
  • None of these helped? – Randy Casburn Commented Feb 14, 2021 at 21:46
  • did you solve this issue, I am also facing same issue – Avinash A Commented Dec 29, 2023 at 11:21
  • I implemented all of the suggested answers and got my problem solved. Thank you community! – stanley_manley Commented Jun 19, 2024 at 21:58
Add a comment  | 

4 Answers 4

Reset to default 13

Not sure if you had implemented routing in ReactJS, but I fixed by using HashRouter instead of BrowserRouter... example:

return (
    <HashRouter>
        <div>
        <Header/>
            <Switch>
             <Route path="/" component={Home} exact/>
             <Route path="/news" component={News} exact/>
             <Route path="/store" component={Store} exact/>
             <Route path="/login" component={Login} exact/>
             <ProtectedRoute path="/profile" component={Profile} exact/>
           </Switch>
        </div> 
      </HashRouter>
  )

Incase someone stumbles upon this like I did, I solved my issue by changing

win.loadURL(isDev? "http://localhost:3000": `file://${__dirname}/../build/index.html`);

to

mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
  }));

ensure you require path and url and also let mainwindow

const path = require("path");
const url = require('url');

let mainWindow;

also I changed

win.on("closed", () => (mainWindow = null));

to

mainWindow.on("closed", () => (mainWindow = null));

I also change router history to hash

import { createHashHistory } from 'history';
export default createHashHistory();

This problem is due to the wrong link between the build folder & entry point of your app

DON’T USE in this way

mainWindow.loadURL(isDev ? ‘http://localhost:3000' : file://${path.join(__dirname, ‘../build/index.html’)});

USE IN THIS WAY

mainWindow.loadURL(isDev ? ‘http://localhost:3000' : file://${__dirname}/../build/index.html);

and if you use React router you must replace (Router) >> (HashRouter)

const { app, BrowserWindow } = require('electron')


       const appURL = app.isPackaged
        ? url.format({
            pathname: path.join(__dirname, "index.html"),
            protocol: "file:",
            slashes: true,
        })
        : "http://localhost:3000";
    mainWindow.loadURL(appURL);

    if (!app.isPackaged) {
        mainWindow.webContents.openDevTools();
    }

本文标签: javascriptGetting blank screen in windows after electronbuilder react electron appStack Overflow