electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.7k stars 1.74k forks source link

"Error: Cannot find module 'jsonfile/utils'" in linux appimage build #8503

Closed cmdcolin closed 1 month ago

cmdcolin commented 2 months ago

"electron-builder@25.0.5"

Latest build of AppImage fails to start with error message:

 ./jbrowse-desktop-v2.15.3-linux.AppImage
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module 'jsonfile/utils'
Require stack:
- /tmp/.mount_jbrowsjehAMT/resources/app.asar/node_modules/electron-updater/node_modules/fs-extra/lib/json/output-json.js
- /tmp/.mount_jbrowsjehAMT/resources/app.asar/node_modules/electron-updater/node_modules/fs-extra/lib/json/index.js
- /tmp/.mount_jbrowsjehAMT/resources/app.asar/node_modules/electron-updater/node_modules/fs-extra/lib/index.js
- /tmp/.mount_jbrowsjehAMT/resources/app.asar/node_modules/electron-updater/out/main.js
- /tmp/.mount_jbrowsjehAMT/resources/app.asar/build/electron.js
-
    at Module._resolveFilename (node:internal/modules/cjs/loader:1232:15)
    at s._resolveFilename (node:electron/js2c/browser_init:2:124039)
    at Module._load (node:internal/modules/cjs/loader:1058:27)
    at c._load (node:electron/js2c/node_init:2:17025)
    at Module.require (node:internal/modules/cjs/loader:1318:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/tmp/.mount_jbrowsjehAMT/resources/app.asar/node_modules/electron-updater/node_modules/fs-extra/lib/json/output-json.js:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1484:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
    at Module.load (node:internal/modules/cjs/loader:1295:32)

if i unzip the app.asar file, i can see that there is a app.asar/node_modules/jsonfile but that is v4, while the fs-extra there wants v6

here are some screenshots, see filename paths pointing the the node_modules directory that i unzipped from the app.asar file with "npx @electron/asar extract app.asar outdir"

image

image

I normally use "yarn" (v1) to install my node_modules in my normal monorepo, but am unsure how the node_modules directory is constructed for this project. I haven't yet traced the exact root cause, but seems something with the node_modules directory format/construction in the app.asar

i update versions of stuff a lot so dont know exactly the cause. this is the entire diff of the yarn.lock between a version that works (did not give the above error) and a version that gave the error. i didn't see anything that really stood out (no fs-extra changes, no jsonfile changes, no electron-builder changes, no electron-updater changes

if i had one question, it would probably be how the node_modules in the app.asar is created?

this is the full diff between a working version of our app and the failing https://github.com/GMOD/jbrowse-components/compare/v2.15.1..v2.15.3/ (v2.15.2 was skipped)

cmdcolin commented 2 months ago

note that the app works on mac. im not currently building any other linux targets

cmdcolin commented 2 months ago

weirdly, this AppImage instance was built via a github action, but if i build it locally, it seemed to work (??)

cmdcolin commented 2 months ago

a similar bug here suggests deleting the lockfile and re-installing https://github.com/storybookjs/storybook/issues/22682 but i am not sure if that would apply in my case because the local build i mention above has the same yarn.lock as the github action

mmaietta commented 2 months ago

@cmdcolin was this working previoiusly on 24.13.3? Just looking to triage if this was recently introduced.

cmdcolin commented 2 months ago

the diff at https://github.com/GMOD/jbrowse-components/compare/v2.15.1..v2.15.3/ actually didnt have anything related to electron builder, electron-updater, fs-extra, or jsonfile (all the culprits from thw stack trace) so it is wuite odd. we previously used electron build3r 24, had a successful release with v25 in with our products v2.15.1, but had this happem in latest v2.15.3

If its too weird a bug could certainly close. thw fact i built the same thing locally instead of via github action akd it worked suggests some nondeterminism or other weird thing (my local is otherwise quite similar to the github action on os, emvironment, etc)

beyondkmp commented 2 months ago

@cmdcolin Could you help to try v25.1.3 ?

cmdcolin commented 2 months ago

I can give it a shot, might be a little bit till i am able to get around to it! am I correct in thinking that the 'conflictDependency' mentioned there could be relevant to this?

cmdcolin commented 1 month ago

found this happened in the windows build exe installer also, i haven't had a chance to update to the electron-builder@next/25.1.x branch yet though

beyondkmp commented 1 month ago

@cmdcolin deploying release v25.1.6 now. Please update when you have a chance

s100 commented 1 month ago

Seeing a similar issue here while trying to upgrade from electron-builder@24 to 25.0.5. The electron-build process completes successfully but attempting to launch the built Electron app gives a popup saying:

[Window Title]
Error

[Main Instruction]
A JavaScript error occurred in the main process

[Content]
Uncaught Exception:
Error: Cannot find module 'string-width'
Require stack:
- C:\...\app.asar\node_modules\cliui\build\index.cjs
- C:\...\app.asar\node_modules\yargs\build\index.cjs
- C:\...\app.asar\node_modules\yargs\index.cjs
- C:\...\app.asar\node_modules\nconf\lib\nconf\stores\argv.js
- C:\...\app.asar\node_modules\nconf\lib\nconf.js
- ...
    at Module._resolveFilename (node:internal/modules/cjs/loader:1232:15)
    at s._resolveFilename (node:electron/js2c/browser_init:2:124038)
    at Module._load (node:internal/modules/cjs/loader:1058:27)
    at c._load (node:electron/js2c/node_init:2:17025)
    at Module.require (node:internal/modules/cjs/loader:1318:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\...\app.asar\node_modules\cliui\build\index.cjs:291:21)
    at Module._compile (node:internal/modules/cjs/loader:1484:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
    at Module.load (node:internal/modules/cjs/loader:1295:32)

[OK]

string-width is indeed a production dependency of cliui so I don't see why it would not be making its way into the ASAR.

This is with no changes to our config. If there are breaking/API changes for electron-builder@25 I wasn't able to find any.

beyondkmp commented 1 month ago

@s100 v25.1.6 has fixed this bug. Please try it.

osztenkurden commented 1 month ago

Im having similiar issue (but with archiver-utils package, dependency of exceljs), with basically all 25+ version, 24.2.0 works properly though

KillerCodeMonkey commented 1 month ago

@osztenkurden the same with archiver-utils. we upgraded electron builder from 25.0.5 to 25.1.7 and electron 32.x

We are using archiver package in your to create zips and never had a problem.

i checked the package-lock and it seems only some squirrel package of eletron-builder depend on archiver-util. i do not know why it is then required for linux/macos builds in our app.

beyondkmp commented 1 month ago

@osztenkurden @KillerCodeMonkey I cannot reproduce the issue you mentioned with the archiver-utils. Could you please provide a minimal reproducible demo?

{
  "name": "TestApp",
  "productName": "Test App ßW",
  "description": "My Electron application description",
  "keywords": [],
  "main": "./main.js",
  "version": "1.0.0",
  "author": "beyondkmp",
  "scripts": {
    "start": "electron .",
    "dist": "electron-builder"
  },
  "license": "MIT",
  "build": {
    "appId": "electron-blog-example",
    "win": {
      "target": "nsis"
    }
  },
  "devDependencies": {
    "electron": "32.1.0",
    "electron-builder": "25.1.7"
  },
  "dependencies": {
     "exceljs":"4.4.0",
    "archiver-utils":"5.0.2",
    "archiver":"7.0.1"
  }
}
KillerCodeMonkey commented 1 month ago

@beyondkmp please do not install archiver-utils as dependency

I never had it in my package.json and needed it there. It should be automatically installed as dependency of some squirrel packages. But the error occurs on macos (dmg) and linux (AppImage) as well.

So it can not be that all of a sudden i have to install prod dependencies in my project, that i do not use directly.

PS: sure when i add the dependency to my package.json it is working... but i do not want to have dependencies there that i do not really use and nobody knows why it is there..

beyondkmp commented 1 month ago

@KillerCodeMonkey Thanks. It will be fixed in https://github.com/develar/app-builder/pull/143

KillerCodeMonkey commented 1 month ago

noice! thank you for the fast response.