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

electron-builder packages with wrong electron binary version #3984

Closed
thomasnordquist opened this issue Jun 18, 2019 · 10 comments
Closed

electron-builder packages with wrong electron binary version #3984

thomasnordquist opened this issue Jun 18, 2019 · 10 comments
Labels

Comments

@thomasnordquist
Copy link

thomasnordquist commented Jun 18, 2019

  • Version: 20.44.1
  • Target: mac / snap / nsis/ appx ....

I have [email protected] installed but when I package, electron-builder downloads [email protected] which is not the version I developed and tested with. This may lead to very unfortunate bugs/incompatibilities.

Details:
electron-builder appears to rely on the electron version provided in package.json and ignores installed/locked versions.
A version string like ^5.0.0 can be understood as 5.0.0 >= allowed versions > 6.0.0.

Example
While version 5 is specified in package.json

"dependencies": {
    "electron": "^5",
    "electron-builder": "20.44.1"
}

The package manager may/will choose to install more recent packages:
yarn.lock

electron@5:
  version "5.0.4"
  resolved "https://registry.yarnpkg.com/electron/-/electron-5.0.4.tgz#2e0d09055363e983f4a73317cde4821c39617b02"
  integrity sha512-7QaKorvANvP+azMT7wElx33oLlqw8QxmLs7/outfH7LC5amErk4EUtWDesQ6Zgr+s5pYFbykl8ZtJ4ZGXER05g==
  dependencies:
    "@types/node" "^10.12.18"
    electron-download "^4.1.0"
    extract-zip "^1.0.3"

yarn.lock or package-lock.json do reflect the actual used package versions.

The workaround is to set the specific electron version in the package.json dependencies, this is however not the way one normally uses the package manager since lock files exist. (and will most certainly interfere with greenkeeper and depandabot)

Just noticed this by accident, packaging using electron 5.0.0 and expecting 5.0.4 (since I specifically updated to 5.0.4) would have caused a lot of headaches.

@develar
Copy link
Member

develar commented Jun 24, 2019

No, electron-builder checks installed version — see

export async function getElectronVersionFromInstalled(projectDir: string) {

Maybe you use custom project dir during build (that not equal to actual project dir, where node modules installed)?

@thomasnordquist
Copy link
Author

You are correct, I use a fresh clone (from .git) to prepare builds in a subdirectory. (to prevent using a dirty workspace by accident)

After building I remove the devDependencies in this subdirectory with yarn install --production, electron-builder can no longer determine the electron version since electron itself is a dev dependency.

I can confirm that the issue does not occur when the dev-dependencies are present/installed.

@develar
Copy link
Member

develar commented Jun 25, 2019

Another workaround for such build scripts: pass CLI arg -c.electronVersion or set config "electronVersion": "version".

develar added a commit to develar/electron-builder that referenced this issue Jun 25, 2019
develar added a commit to develar/electron-builder that referenced this issue Jun 25, 2019
tonywoode added a commit to tonywoode/quickPlayNode that referenced this issue Oct 11, 2019
...not hooked up yet, plus electron exists in the parent
repo simply to get its version number, needs sensibly enumerating
instead eg: electron-userland/electron-builder#3984
@sandeep1995
Copy link
Contributor

If you are trying to upgrade to Electron 7.0, make sure your dev dependencies is like the following

"devDependencies": {
    "electron": "7.0.0",
}

Notice it has to be 7.0.0 not ^7.0.0. The parser is poorly written.

@edmofro
Copy link

edmofro commented Feb 23, 2021

If using a yarn-workspaces based mono-repo and seeing "none of the possible electron modules are installed", add the following to your package.json

"workspaces": {
    "nohoist": [
      "electron"
    ]
  }

This forces yarn to keep electron in the package node_modules rather than hoisting it up to the root (where electron-builder doesn't seem to spot it)

bemasc pushed a commit to Jigsaw-Code/outline-server that referenced this issue Jun 16, 2021
electron-builder cannot tolerate electron versions that are specified
with semantic versioning syntax: electron-userland/electron-builder#3984 (comment)

This change also adds release builds to the presubmit, to prevent
regressions.
@AgainPsychoX
Copy link

AgainPsychoX commented Aug 20, 2021

I have similar issue while using npm workspaces. I have structure

root/             // Main folder, workspaces root
root/app/         // My app, no real `node_modules` here
...               // The app is just using node_modules of its workspace,
root/node_modules // <-- this one. And there is `electron`, yet, its not directly in the project (the app) directory, so can't find the version...
...

Maybe the getElectronVersionFromInstalled could check directory above if the project is using workspaces?

Or, why can't the version be extracted from package-lock.json?

@steveruizok
Copy link

steveruizok commented Nov 7, 2021

The fix for me was replacing electron: "^15.3.0" with electron: "15.3.0" in my package.json's devDependencies.

@noor-tg
Copy link

noor-tg commented Dec 7, 2021

@develar solution is best for monorepos

@tresorama
Copy link

If using a yarn-workspaces based mono-repo and seeing "none of the possible electron modules are installed", add the following to your package.json

"workspaces": {
    "nohoist": [
      "electron"
    ]
  }

This forces yarn to keep electron in the package node_modules rather than hoisting it up to the root (where electron-builder doesn't seem to spot it)

Working in a Yarn monorepo workspace this solution worked!
But in my case the glob pattern should be edited like this to make it nohoisting every electron-ish packages

"workspaces": {
    "packages":[
      "apps/*"
    ],
    "nohoist": [
      "**electron**"
    ]
  },

Thank you @develar ! 😎

kon72 added a commit to kon72/turboscript that referenced this issue Jun 23, 2023
Normally electron-builder will look inside `node_modules` to detect the version of electron installed, but it's not likely to look for hoisted one, and falls back to search from `dependencies` entry in package.json.
This change is a workaround for the following error:

Cannot compute electron version from installed node modules - none of the possible electron modules are installed and version ("^25.1.1") is not fixed in project.

See electron-userland/electron-builder#3984 (comment)
nop33 added a commit to nop33/alephium-frontend that referenced this issue Nov 8, 2023
dkarski added a commit to mudita/mudita-center that referenced this issue Apr 3, 2024
…tection

# Configured project to prevent hoisting of Electron dependency, fixing an issue where electron-builder could not correctly identify the installed Electron version. This adjustment is crucial for accurate application packaging and notarization.
# Reference: electron-userland/electron-builder#3984
@Dhruv7201
Copy link

electron version to 7.0.1; update electron-builder to 22.4.0

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

No branches or pull requests

10 participants