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.61k stars 1.74k forks source link

NextJS Dynamic Rendering through Electron-Builder: Possible Bundling Issue #8466

Open Forsyth-Creations opened 2 weeks ago

Forsyth-Creations commented 2 weeks ago

electron-builder: 25.0.5:

Node: 22.6.0:

Electron: 32.0.2:

Building: main.js:

I'm working on a NextJS application, but I'm doing something out of the ordinary: instead of building the static site, I'm trying to use NextJS to serve the frontend at a random port and then allow Electron to access that page. Whenever I package it up with the builder (On Windows) all the files are in the app.asar as I'd expect but the application fails to find the .next folder. Running main.js locally though Electron has no such error, so I assume this has something to do with how I'm packaging it with the builder or NextJS. I've included pertinent files in this post, please let me know if I'm missing something!

CodeSegments.zip

Electron started
Running in production mode
Found open port 8021
Next.js app created
Next.js serving files from C:\Users\rober\AppData\Local\Programs\padua\resources\app.asar\
(node:28196) UnhandledPromiseRejectionWarning: Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root
    at findPagesDir (C:\Users\rober\AppData\Local\Programs\padua\resources\app.asar\node_modules\next\dist\lib\find-pages-dir.js:42:15)
    at initialize (C:\Users\rober\AppData\Local\Programs\padua\resources\app.asar\node_modules\next\dist\server\lib\router-server.js:76:69)
    at async NextCustomServer.prepare (C:\Users\rober\AppData\Local\Programs\padua\resources\app.asar\node_modules\next\dist\server\next.js:242:28)
(Use `padua --trace-warnings ...` to show where the warning was created)
(node:28196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
mmaietta commented 2 weeks ago

I think this may be issue let myPath = path.join(__dirname, '../'); as that'll work in development, but in production, I think you need to use app.getAppPath() to point at the file https://www.electronjs.org/docs/latest/api/app/#appgetapppath