electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.65k stars 1.74k forks source link

Electron builder app is not opening in mac - error "app can't be opened" #7486

Closed shanjairaj7 closed 1 year ago

shanjairaj7 commented 1 year ago

Once I open the built app, this is error I am getting

image

image

I am trying to build the electron and react app for mac, and once I open the app, I am getting an error saying the app can't be opened.

I am using React router for the routing and I am loading the URL for the app with index.html#/onboarding when I am creating a the menubar window and the normal window.

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@electron/remote": "^2.0.9",
    "@react-spring/web": "^9.7.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.2.3",
    "buffer": "^6.0.3",
    "date-fns": "^2.29.3",
    "dayjs": "^1.11.7",
    "electron-browser-storage": "^1.0.7",
    "electron-store": "^8.1.0",
    "fs": "^0.0.1-security",
    "menubar": "^9.2.3",
    "node-schedule": "^2.1.1",
    "pusher-js": "^8.0.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-html-parser": "^2.0.2",
    "react-icons": "^4.7.1",
    "react-loader-spinner": "^5.3.4",
    "react-router-dom": "^6.8.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "main": "public/electron.js",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "dev": "concurrently -k \"npm start\" \"npm:electron\"",
    "electron": "wait-on tcp:3000 && electron .",
    "electron:serve": "concurrently -k \"cross-env BROWSER=none yarn start\" \"yarn electron:start\"",
    "electron:build": "yarn build && electron-builder -c.extraMetadata.main=build/electron.js",
    "electron:start": "wait-on tcp:3000 && electron ."
  },
  "build": {
    "extends": null,
    "appId": "com.example.app",
    "files": [
      "dist/**/*",
      "build/**/*",
      "node_modules/**/*",
      "package.json"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },
  "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": "^7.6.0",
    "electron": "^22.0.2",
    "electron-builder": "^23.6.0",
    "electron-is-dev": "^2.0.0",
    "wait-on": "^7.0.1"
  }
}

Electron window config


const createMenubar = () => {
  let mb = menubar({
    index: app.isPackaged
      ? url.format({
          pathname: path.join(__dirname, "index.html#/home"),
          protocol: "file:",
          slashes: true,
        })
      : "http://localhost:3000",
    browserWindow: {
      width: 550,
      height: 675,
      show: true,
      icon: path.join(__dirname, "logo.png"),
      webPreferences: {
        nodeIntegration: false, // Default is false
        contextIsolation: true, // Default is true
        preload: path.join(__dirname, "preload.js"), // Use of preload.jsc
        backgroundThrottling: false,
        // preload: path.join(__dirname, 'preload-alt.js')  // Use of preload-alt.js
      },
    },
  });

  mb.on("ready", () => {
    mb.showWindow();

    mb.tray.setImage(path.join(__dirname, "IconTemplate.png"));
    mb.window.setIcon(path.join(__dirname, "Logo.png"));

    if (isDev) mb.window.webContents.openDevTools({ mode: "detach" });
  });
};

This is the folder structure, please let me know if this is right for building electron react apps with routing.

image
lurdbinanc commented 1 year ago
  • Electron-Builder Version: ^23.6.0

  • Node Version: v14.19.1

  • Electron Version: ^22.0.2

  • Electron Type (current, beta, nightly): current

  • Target: mac m1

Once I open the built app, this is error I am getting

image

image

I am trying to build the electron and react app for mac, and once I open the app, I am getting an error saying the app can't be opened.

I am using React router for the routing and I am loading the URL for the app with index.html#/onboarding when I am creating a the menubar window and the normal window.


{

  "name": "app",

  "version": "0.1.0",

  "private": true,

  "dependencies": {

    "@electron/remote": "^2.0.9",

    "@react-spring/web": "^9.7.1",

    "@testing-library/jest-dom": "^5.16.5",

    "@testing-library/react": "^13.4.0",

    "@testing-library/user-event": "^13.5.0",

    "axios": "^1.2.3",

    "buffer": "^6.0.3",

    "date-fns": "^2.29.3",

    "dayjs": "^1.11.7",

    "electron-browser-storage": "^1.0.7",

    "electron-store": "^8.1.0",

    "fs": "^0.0.1-security",

    "menubar": "^9.2.3",

    "node-schedule": "^2.1.1",

    "pusher-js": "^8.0.1",

    "react": "^18.2.0",

    "react-dom": "^18.2.0",

    "react-html-parser": "^2.0.2",

    "react-icons": "^4.7.1",

    "react-loader-spinner": "^5.3.4",

    "react-router-dom": "^6.8.0",

    "react-scripts": "5.0.1",

    "web-vitals": "^2.1.4"

  },

  "main": "public/electron.js",

  "scripts": {

    "start": "react-scripts start",

    "build": "react-scripts build",

    "test": "react-scripts test",

    "eject": "react-scripts eject",

    "dev": "concurrently -k \"npm start\" \"npm:electron\"",

    "electron": "wait-on tcp:3000 && electron .",

    "electron:serve": "concurrently -k \"cross-env BROWSER=none yarn start\" \"yarn electron:start\"",

    "electron:build": "yarn build && electron-builder -c.extraMetadata.main=build/electron.js",

    "electron:start": "wait-on tcp:3000 && electron ."

  },

  "build": {

    "extends": null,

    "appId": "com.example.app",

    "files": [

      "dist/**/*",

      "build/**/*",

      "node_modules/**/*",

      "package.json"

    ],

    "directories": {

      "buildResources": "assets"

    }

  },

  "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": "^7.6.0",

    "electron": "^22.0.2",

    "electron-builder": "^23.6.0",

    "electron-is-dev": "^2.0.0",

    "wait-on": "^7.0.1"

  }

}

Electron window config


const createMenubar = () => {

  let mb = menubar({

    index: app.isPackaged

      ? url.format({

          pathname: path.join(__dirname, "index.html#/home"),

          protocol: "file:",

          slashes: true,

        })

      : "http://localhost:3000",

    browserWindow: {

      width: 550,

      height: 675,

      show: true,

      icon: path.join(__dirname, "logo.png"),

      webPreferences: {

        nodeIntegration: false, // Default is false

        contextIsolation: true, // Default is true

        preload: path.join(__dirname, "preload.js"), // Use of preload.jsc

        backgroundThrottling: false,

        // preload: path.join(__dirname, 'preload-alt.js')  // Use of preload-alt.js

      },

    },

  });

  mb.on("ready", () => {

    mb.showWindow();

    mb.tray.setImage(path.join(__dirname, "IconTemplate.png"));

    mb.window.setIcon(path.join(__dirname, "Logo.png"));

    if (isDev) mb.window.webContents.openDevTools({ mode: "detach" });

  });

};

This is the folder structure, please let me know if this is right for building electron react apps with routing.

image
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.

AzerAliyev11 commented 1 year ago

Did you find a solution? I am having the same problem

Hikk0o commented 5 months ago

@AzerAliyev11 @shanjairaj7 Same