electron-builder: Production build: unusable binary dependencies (Unexpected end of JSON input)
- Version: v22.9.1
- Electron Version: v11.0.0-beta.13
- Electron Type (current, beta, nightly): beta
- Target: macOS 10.15.2
- Node Version: v12.16.1
- Last Known Working Electron version: v10.1.4
- Package manager version Yarn 1.22.10 (or NPM 6.13.4)
Hello,
We are having an issue when building our application with version 11-beta using electron-builder (the behavior changed between version 10.x and 11 of Electron). We rely on static binaries to be included in our build (ffmpeg, to name it), but when starting the built app we get a JS error saying the package.json file for this module is invalid (Unexpected end of JSON input). When looking at the content of the generated .app the (unpacked) app.asar has properly included the dependencies, and the package.json is valid.
The project runs fine on dev, it’s the finalized built version that has an issue. I created a repo with the base project, as well as uploaded the built version in the 1.0.0 release of this repo.
$ git clone https://github.com/lmancel/electron-tests.git
$ yarn install
$ yarn build
Built binary: https://github.com/lmancel/electron-tests/releases/download/1.0.0/electron-test-1.0.0-mac.zip
Screenshots


About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 17 (7 by maintainers)
Commits related to this issue
- fix(player) removed stream re-encoding only re-encapsulate from mpegts to mp4 also do not use asar archive for build as it is not working well with external dependencies --> see https://github.com/el... — committed to taktik/flowr-desktop by lmancel 4 years ago
- Revert "Upgrade to Electron 11." It causes problems with electron-builder. See https://github.com/electron-userland/electron-builder/issues/5360 This reverts commit 4e9cee1642a4d4046c174e0a9b0f7705f... — committed to firoorg/firo-client by sproxet 4 years ago
- Feat/custom electron build (#34) * fix(version) update electron to 10.1.4 And fix the breaking changes * fix(player) removed stream re-encoding only re-encapsulate from mpegts to mp4 also d... — committed to taktik/flowr-desktop by lmancel 3 years ago
It turned out not to be
electron-builderrelated, see https://github.com/electron/electron/issues/26819.I found a fix, exclude the packages with asarUnpack option:
and then from now on require these modules like this in your code:
(instead of
require('MODULE_NAME'), note this does not work in dev, so you need to have an if statement)If you use Webpack however, it’s simple, just use this in your webpack.config.js instead:
(replace
MODULE_NAMEwith names of the packages you excluded, for each of them you need to add a record to the externals config)Verified that its fixed in electron
11.1.0!asar:falsebe gone!