question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

Screenshot 2020-10-21 at 16 41 49

Screenshot 2020-10-21 at 16 50 46

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
vladimirycommented, Dec 3, 2020

It turned out not to be electron-builder related, see https://github.com/electron/electron/issues/26819.

6reactions
momakes2commented, Nov 29, 2020

I found a fix, exclude the packages with asarUnpack option:

 "asarUnpack": [
      "**/*.node",
      "**/node_modules/is-typings/**/*",
      "**/node_modules/@sindresorhus/do-not-disturb/**/*",
      "**/node_modules/@morajabi/robotjs/**/*",
...
]

and then from now on require these modules like this in your code:

require(require('path').join(__dirname.replace('app.asar', 'app.asar.unpacked'), 'node_modules/MODULE_NAME'))

(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:

externals: {
   MODULE_NAME: IS_PROD
    ? `require(require('path').join(__dirname.replace('app.asar', 'app.asar.unpacked'), 'node_modules/${name}'))`
    : `commonjs2 ${name}`
}

(replace MODULE_NAME with names of the packages you excluded, for each of them you need to add a record to the externals config)

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM Install Error:Unexpected end of JSON input while ...
The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux)...
Read more >
Unexpected end of JSON input error occurred when executing ...
The solution is simple. The yarn global cache need to be cleaned. yarn cache clean. Adding the --force parameter may be needed. There...
Read more >
Learning the Basics - Gradle User Manual
Organizations building software may want to leverage public binary repositories to download and consume open source dependencies.
Read more >
How to make a beautiful, tiny npm package and publish it
TL;DR An npm module only requires a package.json file with name and version ... Unexpected end of JSON input while parsing near ''...
Read more >
Troubleshooting Node.js Deploys - Heroku Dev Center
Heroku will output which binaries (ie. node , npm ) are used for each ... the devDependencies from the package.json at the end...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found