Electron-builder cannot find module <electron-is-dev> after running exe file

Viewed 423

I have an Electron app which runs fine on VS Code dev npm run dev but when I publish the app using electron-builder and run .exe file from dist folder I get the error which is attached below:

Error after I run .exe file

package.json

  "name": "jokes_collection_fe",
  "version": "0.1.0",
  "private": true,
  "main": "public/electron.js",
  "dependencies": {
    "@emotion/react": "^11.5.0",
    "@emotion/styled": "^11.3.0",
    "@mui/icons-material": "^5.1.0",
    "@mui/material": "^5.1.0",
    "@testing-library/jest-dom": "^5.15.0",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "axios": "^0.24.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.6",
    "react-scripts": "4.0.3",
    "react-toastify": "^8.1.0",
    "redux": "^4.1.2",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.4.0",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "dev": "concurrently -k \"SET BROWSER=none&&npm start\" \"npm:electron\"",
    "electron": "wait-on tcp:3000 && electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder"
  },
  "build": {
    "appId": "Jokes Collection",
    "extends": null,
    "win": {
      "target": "nsis",
      "icon": "build/icon.png"
    }
  },
  "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"
    ]
  },
  "devDependencies": {
    "concurrently": "^6.4.0",
    "electron": "^16.0.4",
    "electron-builder": "^22.14.5",
    "electron-is-dev": "^2.0.0",
    "wait-on": "^6.0.0"
  }
}

public/Electron.js

const path = require("path")
const { app, BrowserWindow } = require("electron")
const isDev = require("electron-is-dev")
function createWindow() {
const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  })
  win.loadURL(
    isDev
      ? "http://localhost:3000"
      : `file://${path.join(__dirname, "../build/index.html")}`
  )
  if (isDev) {
     win.webContents.openDevTools({ mode: "detach" })
  }
}
app.whenReady().then(createWindow)
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit()
  }
})
app.on("activate", () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createW`enter code here`indow()
  }
})
0 Answers
Related