Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package causing error on app open #162

Open
whospsycho opened this issue Nov 1, 2024 · 6 comments
Open

Package causing error on app open #162

whospsycho opened this issue Nov 1, 2024 · 6 comments

Comments

@whospsycho
Copy link

Hi, I'm having an issue where whenever I build my application into a ZIP or a DMG for macOS/darwin and I open the application, it returns the error:

Error: Cannot find module 'update-electron-app'
Require stack:
- /Users/user/Documents/Appname/electron/out/Appname-darwin-arm64/Appname.app/Contents/Resources/app.asar/.vite/build/main.js
- 
at Module._resolveFilename (node:internal/modules/cjs/loader:1232:15)
at s._resolveFilename (node:electron/js2c/browser_init:2:123740)
at Module._load (node:internal/modules/cjs/loader:1058:27)
at c._load (node:electron/js2c/node_init:2:16955)
at Module.require (node:internal/modules/cjs/loader:1318:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/Users/user/Documents/Appname/electron/out/Appname-darwin-arm64/Appname.app/Contents/Resources/app.asar/.vite/build/main.js:1:208)
at Module._compile (node:internal/modules/cjs/loader:1484:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
at Module.load (node:internal/modules/cjs/loader:1295:32)

My forge config:

const config: ForgeConfig = {
  packagerConfig: {
    asar: true,
    icon: "./src/assets/logo.ico",
    protocols: [
      {
        name: "Appname",
        schemes: ["appname"]
      }
    ]
  },
  rebuildConfig: {},
  makers: [
    {
      name: "@electron-forge/maker-squirrel",
      config: (arch: any) => ({
        loadingGif: "./src/assets/loading.gif",
        iconUrl: "https://s3.appname.com/static/appname-logo.svg",
        setupIcon: `./src/assets/logo.ico`,
        remoteReleases: `https://s3.appname.com/appname/releases/win32/${arch}`,
      }),
    },
    {
      name: "@electron-forge/maker-zip",
      config: {
        platform: "darwin",
      }
    }
  ],
  publishers: [
    {
      name: '@electron-forge/publisher-s3',
      config: {
        bucket: 'Appname',
        keyResolver: (fileName: any, platform: any, arch: any) => {
          return `Appname/releases/${platform}/${arch}/${fileName}`
        },
        public: true,
        region: 'auto',
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        endpoint: process.env.AWS_ENDPOINT_URL,
        folder: 'Appname'
      }
    }
  ],
  plugins: [
    new VitePlugin({
      // `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
      // If you are familiar with Vite configuration, it will look really familiar.
      build: [
        {
          // `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
          entry: "src/main.ts",
          config: "vite.main.config.ts",
        },
        {
          entry: "src/preload.ts",
          config: "vite.preload.config.ts",
        },
        {
          entry: "src/webviewpreload.ts",
          config: "vite.preload.config.ts",
        }
      ],
      renderer: [
        {
          name: "main_window",
          config: "vite.renderer.config.ts",
        },
      ],
    }),
    // Fuses are used to enable/disable various Electron functionality
    // at package time, before code signing the application
    new FusesPlugin({
      version: FuseVersion.V1,
      [FuseV1Options.RunAsNode]: false,
      [FuseV1Options.EnableCookieEncryption]: true,
      [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
      [FuseV1Options.EnableNodeCliInspectArguments]: false,
      [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
      [FuseV1Options.OnlyLoadAppFromAsar]: true,
    }),
  ],
};

export default config;

I'm running on macOS Monterey 12.5 and Bun 1.1.33.
I've tried multiple times to remove all node_modules, reinstall them, update them, etc, but nothing seems to fix my problem.
Any help would be greatly appreciated, thanks.

@edymusajev
Copy link

Same issue, I haven't touched this code in my app for months but now suddenly it breaks the app

@edymusajev
Copy link

@whospsycho I got a temporary solution that works for me

It's related to the issues mentioned here:

I followed these steps (some of these might be unneeded, not sure):

  1. Make sure "electron-squirrel-startup" and "update-electron-app" is in devDependencies and not dependencies
  2. downgrade all electron-forge packages to 7.4.0
  3. change electron-squirrel-startup in your main.ts:

Before:

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require("electron-squirrel-startup")) {
  app.quit();
}

Modify to:

// @ts-expect-error no types
import started from "electron-squirrel-startup";

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (started) {
  app.quit();
}

@whospsycho
Copy link
Author

whospsycho commented Nov 6, 2024

@edymusajev Your fix seems to have worked perfectly, although I left out the downgrading electron-forge step. Thanks for your help! I'll leave this issue open for the time being.

@hichemfantar
Copy link

hichemfantar commented Nov 7, 2024

You you can do this instead of downgrading.
temp workaround is to disable asar by modifying the following properties in forge.config.ts

const config: ForgeConfig = {
  packagerConfig: {
    asar: false,
  },
  plugins: [
    new FusesPlugin({
      [FuseV1Options.OnlyLoadAppFromAsar]: false,
    }),
  ],
};

@abhijith-rubrik
Copy link

+1

@WilliamColton
Copy link

WilliamColton commented Nov 19, 2024

I also encountered this issue, but I resolved it by changing the import statement to:

import { updateElectronApp } from "update-electron-app";
import started from "electron-squirrel-startup";

updateElectronApp({})

if (started) {
    app.quit();
}

I hope this helps you as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants