Electron ERR_CONNECTION_REFUSED to localhost:3000 Since Build

Viewed 16

I've been working on a small app with React/Electron, and so far things are working out. Building it is a bit complicated for me. Ever since I've built this application, I can no longer run npm run dev to develop this app locally (localhost:3000), I get this error:

 electron: Failed to load URL: http://localhost:3000/ with error: ERR_CONNECTION_REFUSED

I've checked with electron is dev and we are still currently in development.

My loadURL is fairly simple:

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

These are my package.json scripts:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "dev": "wait-on tcp:3000 && concurrently -k \"npm:electron\"",
    "electron": "electron .",
    "electron:package:mac": "yarn build && electron-builder -m -c.extraMetadata.main=build/electron.js",
    "electron:package:win": "yarn build && electron-builder -w -c.extraMetadata.main=build/electron.js",
    "electron:package:linux": "yarn build && electron-builder -l -c.extraMetadata.main=build/electron.js"
  },

I read a thread on stackoverflow that mentioned to switch loadURL to the index in build folder, which it will load there but it doesn't show the updates I'm working on until I actually build the app.

I've also tried to kill-port 3000, and still getting the same issue.

Any help would be appreciated.

Thanks.

0 Answers
Related