electron-builder: Yarn 3 module rebuild failing

  • Electron-Builder Version: 24.9.1
  • Node Version: 20.1.0
  • Electron Version: 28.2.1
  • Electron Type (current, beta, nightly): current
  • Target: macOS

When moving from Yarn 1 to Yarn 3 there is now an issue when rebuilding a module. This issue was not a problem with Yarn 1. I did some debugging and rebuild seems to be working fine with @electron/rebuild. I can even get it working if I use v24.6.0 of app-builder-lib (when it used @electron/rebuild). But it seems to be broken when using Electron Builder’s rebuild functionality.

Here is a repro that you can clone: https://github.com/davej/electron-boilerplate-yarn-3-issue

To recreate simple clone the repo and run yarn. After install has finished then you should see output that ends like this:

➤ YN0009: │ electron-boilerplate@workspace:. couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/h1/9dzghzlx0xgcdw3j5yjk0hg00000gn/T/xfs-bc5c23f7/build.log)
➤ YN0000: └ Completed in 5s 484ms
➤ YN0000: Failed with errors in 44s 972ms

If you click into the logs then you will see something like this:

# This file contains the result of Yarn building a package (electron-boilerplate@workspace:.)
# Script name: postinstall

  • electron-builder  version=24.9.1
  • loaded configuration  file=package.json ("build" field)
  • rebuilding native dependencies  dependencies=@bugsnag/plugin-electron-app@7.22.2, @bugsnag/plugin-electron-client-state-persistence@7.22.2 platform=darwin arch=arm64
  • rebuilding native dependency  name=@bugsnag/plugin-electron-client-state-persistence version=7.22.2
  • rebuilding native dependency  name=@bugsnag/plugin-electron-app version=7.22.2
  ⨯ cannot execute  cause=exit status 1
                    out=Usage Error: Couldn't find a script named "install".

$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

                    command=/private/var/folders/h1/9dzghzlx0xgcdw3j5yjk0hg00000gn/T/xfs-b1ba03f1/yarn run install
                    workingDir=/Users/davejeffery/code/test/electron-boilerplate-yarn-3-issue/node_modules/@bugsnag/plugin-electron-app

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 21 (9 by maintainers)

Most upvoted comments

Hmmm, that would be a breaking API change for users, so I’m cautious in doing that.

I presume you’re referring to the beforeBuild return value? It might technically be a breaking change but it won’t break any existing behavior because nobody will be using that string.

Maybe I can add a process.env.OVERRIDE_xxx to the logic so that you can explicitly override the functionality for now at least.

Sounds good to me but just to be clear, I have manually patched the library so there is no pressure from my end to resolve this. 😊

Actually, I think I figured it out. Looking at your dependencies package.json, it only no install step, and that seems to be confusing app-builder

Added a blank "install": "" entry in the dependency’s package.json and yarn install works perfectly fine

My recommendation is to test editing the dependencies package.json

  1. node_modules/@bugsnag/plugin-electron-app
  2. node_modules/@bugsnag/plugin-electron-client-state-persistence/package.json

Use this:

  "scripts": {
    "install": "",
    "build": "node-gyp configure build",
    ...
  }

These changes can be persisted in your repo via patch-package if it works for you. Tested the distributable locally and your app runs, not sure what logic triggers the native binaries though, but they’re indeed in the package Screenshot 2024-02-01 at 4 14 38 PM