Production build: unusable binary dependencies (Unexpected end of JSON input)
See original GitHub issue- 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:17 (7 by maintainers)
Top GitHub Comments
It turned out not to be
electron-builder
related, 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_NAME
with names of the packages you excluded, for each of them you need to add a record to the externals config)