'Electron Blank Screen Error When Referencing Components
Good afternoon all,
I am trying to import some React components from another application of mine, into my new Electron app. On the new Electron app, I changed aspects of index.html, so that I can reference ‘root’ in my App.js component(which I imported from my react-app to the electron app). I also imported my index.js from my react app into my new electron app, and nested it in the src file.
The Problem:
I am currently getting back a blank screen, and am not sure why. It might be that i referenced some files incorrectly, or a routing issue, but I’m not certain. (Picture of Screen Attached Below)
File Directory:
The Code:
App.js:
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import {
BrowserRouter as Router,
} from "react-router-dom";
import NavbarA from './src/components/NavbarA';
function App() {
return (
<div>
<Router>
<NavbarA/>
</Router>
</div>
);
}
export default App;
Main.js
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
Index.html
<!DOCTYPE html>
<html>
<div id="root"></div>
<title>Spotify</title>
<!-- You can also require other files to run in this process -->
<script src="./App.js>"></script>
</html>
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
Package.json
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^18.2.0"
},
"dependencies": {
"bootstrap": "^5.1.3",
"firebase": "^9.7.0",
"react": "^18.1.0",
"react-audio-player": "^0.17.0",
"react-bootstrap": "^2.3.1",
"react-is": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1"
}
}
Let Me Know What You Think!
Best,
-Zpo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


