fix: configure Prisma for packaged Electron app #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Fix: Configure Prisma for packaged Electron app
Fixes issue where Prisma cannot find query_compiler_bg.sqlite.mjs when running in production (packaged app)
Description
This hotfix resolves a critical production issue where the packaged Electron application fails to load Prisma's query engine. When the app is packaged with electron-builder and asar, Prisma cannot locate the query engine binaries (query_compiler_bg.sqlite.mjs), causing the application to be completely non-functional in production environments.
The fix configures the correct paths for Prisma's query engine binaries in the app.asar.unpacked directory and ensures all necessary Prisma files are included in the packaged build.
Goal
Fix the "Cannot find query_compiler_bg.sqlite.mjs" error that occurs when running the packaged application in production by properly configuring Prisma query engine paths for electron apps packaged with asar.
Key Changes
main.tsto detect and set correct PRISMA_QUERY_ENGINE paths when running in packaged modenode_modules/.prisma/**/*in the packaged filesbuildanddev) to automatically generate Prisma client before compilationType of Change
Impact Assessment
Database Impact
This fix only affects how Prisma locates its query engine in production. No database schema changes or migrations are included.
Backup Impact
This fix does not affect backup or restore functionality. Database operations remain unchanged.
Testing
How Has This Been Tested?
The fix has been manually tested by building and packaging the application, then running it in a production-like environment to verify database operations work correctly.
Test Steps
npm run buildto compile the application with Prisma client generationelectron-builder(npm run dist:winfor Windows)Test Configuration
UI Changes
No UI changes. This is a backend/infrastructure fix.
Before
Application would crash or fail to start with console errors:
After
Application starts normally and all database operations work as expected in the packaged application.
Checklist
npm run lintand fixed any issuesnpm testand all tests passnpm run test:electronand all tests passnpm run sonar:checkand the analysis passesBreaking Changes
No breaking changes. This is a hotfix that only affects the production build process and does not change any APIs or user-facing functionality.
Related Issues
Closes #[TBD]
Related to production deployment issues
Additional Context
Technical Background
When Electron packages an application with asar (archive format), Prisma's native query engine binaries cannot be accessed from within the asar archive. Electron-builder has a mechanism to extract certain files to
app.asar.unpacked, but Prisma needs to be explicitly told where to find these binaries through environment variables.Platform-specific Query Engine Files
query_engine-windows.dll.nodelibquery_engine-darwin.dylib.nodelibquery_engine-darwin-arm64.dylib.nodelibquery_engine-debian-openssl-3.0.x.so.nodeWhy Auto-generate Prisma Client
The build scripts now run
npm run prisma:generatebefore compilation to ensure:Files Modified
electron/src/main/main.ts (+35 lines)
package.json (+5, -3 lines)
node_modules/.prisma/**/*to electron-builder files arraybuildanddevscripts to includenpm run prisma:generateReviewer Notes
Critical Testing Points
Please verify:
.exe(or.dmg/.AppImage), not justnpm run devWhy This Is A Hotfix
This issue completely breaks the production application - users cannot use the packaged app at all because database operations fail immediately. This needs to be merged and released as soon as possible.
Future Improvements
Consider adding: