2

I've run into an issue where when I run electron-package on my app and run the built app, when I try to access a route besides the default route I get a net::ERR_FILE_NOT_FOUND. I have a login page and when I try clicking log in I get: POST file:///logIn net::ERR_FILE_NOT_FOUND

this is my electron.js

const electron = require('electron');
const { app, BrowserWindow } = electron;
const path = require('path');
const isDev = require('electron-is-dev');
const url = require('url');

let mainWindow = null;
const createWindow = () => {
    mainWindow = new BrowserWindow({
        width: 1024, height: 1024,
        autoHideMenuBar: true,
        useContentSize: true,
        resizable: true,
        webPreferences: {
            nodeIntegration: true,
            devTools: true
        }

    })


    mainWindow.loadURL(`file://${__dirname}/../build/index.html#/`);

    mainWindow.on('closed', () => mainWindow = null)

    mainWindow.webContents.openDevTools();


}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') { app.quit() }
})

app.on('activate', () => {
    if (mainWindow === null) { createWindow() }
})

package.json

"main": "public/electron.js",
  "homepage": "./",
  "name": "security-tool",
  "version": "0.1.0",
  "private": true,
  "build": {
    "appId": "",
    "extends": null,
    "files": [
      "node_modules/**/*",
      "package.json",
      "electron.js",
      "build/**/*"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },

and just index.js

ReactDOM.render(
  <CookiesProvider>
    <HashRouter>
      <Switch>
        <Route path="/home" component={Home} />
        <Route path="/projects" component={Projects} />
        <Route path="/settings" component={Settings} />
        <Route path="/form" component={Form} />
        <Route exact path="/" component={Login} />
      </Switch>
    </HashRouter>,
  </CookiesProvider>,
  document.getElementById('root')
);

can't show the entire login component but this is the part which has history.push

logIn = async() => {
  let results = await logInEndpoint(this.state.Username, this.state.Password);
      if(results.result === "Success!") {
        const { cookies } = this.props;
 
        cookies.set('userID', results.data[0].USER_ID, { path: '/', maxAge: 3600 });

        this.props.history.push('/home');
      }
      else{
        this.invalidCreds(results.result);
      }
  }
jylin-arch
  • 21
  • 2
  • Please also include the code for your Login component, as the error happened when you're interacting with it. – Nicky Logan Feb 08 '21 at 18:58
  • logIn = async() => { let results = await logInEndpoint(this.state.Username, this.state.Password); if(results.result === "Success!") { const { cookies } = this.props; cookies.set('userID', results.data[0].USER_ID, { path: '/', maxAge: 3600 }); this.props.history.push('/home'); } else{ this.invalidCreds(results.result); } } I believe this is the part that is referenced – jylin-arch Feb 08 '21 at 20:23
  • I'm still not clear on which part of the code flow caused the error. Your login function also has some other functions which are omitted from your post. Try to post the snippets of the code flow related to your login logic: the form component which includes the button that invokes the login function, the loginendpoint function, and the invalidCreds function. – Nicky Logan Feb 09 '21 at 05:58
  • I thought this would just be an error with electron and the file pathing as the err is like a file not found but I will include more of the login logic as well although I'm unsure that that's the issue as it works in dev environment just not packaged – jylin-arch Feb 09 '21 at 13:52

0 Answers0