Migration Error after building with Electron
Hi everyone, thanks for your time and support in advance.
I've come across some topics about migrations with Electron, but I'm still not sure how to proceed. I'm sorry if this is a trivial question, but how can I make it work? I'm using Electron-vite for scaffolding the project, and in development, it works, but throws an
error after the build.
drizzle.config.ts:
src/database/index.ts:
error:
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Can't find meta/_journal.json file
at readMigrationFiles
(C:\Users\vitor\AppData\Local\Temp\2c5Ed9Qx4OlrkQZpC5qycYknJCU\resources\app.a..11)
at Object.migrate
(C:\Users\vitor\AppData\Local\Temp\2c5Ed9Qx4OIrkQZpC5qycYknJCU\resources\app.a...61)
at Object. < anonymous>
C\Users\vitor\AppData\Local\Temp\2c5Ed9Qx4OlrkQZpC5qycYknJCU\resources\app.a...10)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module. _extensions.js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module.load (node:internal/modules/cjs/loader:967:12)
at c. load (node:electron/js2c/node_init:2:13672)
at node:electron/js2c/browser_init:2:119675
at node:electron/js2c/bropvser_init:2;119884
8 Replies
Hey! Most likely you need to copy this folder manually into the output bundle. Since these assets are not actually copied automatically
Hey, I encountered exactly same problem, I'm building my main process with webpack and added this this webpack config that builds for prod
even when I did that drizzle still can't find migration folder and I think thats because file path that I setup in drizzle.confg.ts is not coresponding with right folder after I build the app any idea what could i change?
Hey man! I was actually trying to solve this right now then I saw your message lol. I've been fighting against this for a while now, and I remembered this morning that I used userData path to create the database file in in the same place it will be after build. Then I'm trying to do the same with migrations folder.
Notice that I used this dynamic dbPath variable which uses userDataPath to create the database file in an absolute location that works fine after build as well. I was looking for do the same thing with migrations folder something with same idea as your approach.
Ok so here is what I did
1. Changed place where migrations are stored from earlier
Now my dist folder looks like this
2. I changed my
drizzle.config.ts
to be relative to path depending if im in production environment (not sure if that does anything tbh but did it just in case)
3. I modified my database setup function to get path to migration directory using __dirname
like this
After i created path to migrations folder with __dirname
it started working just fine
Hope this helps, if you have any other questions let me knowI see 👏 ,very clever! now I've to get it done with this electron-vite template I'm testing https://electron-vite.org/guide/. I'm not sure if they use webpack, I will check in docs but you helped a lot, now I lest I know what I need to learn to get it done. 😁 Thnx!
Getting Started | electron-vite
Next generation Electron build tooling based on Vite.
They use vite instead of webpack not sure how to accomplish the same thing there but I bet you should look if you even have migration folder inside dist file and if not adjust vite config to clone. When you have that working my sollution should work just fine
You should edit main part of that most likely
https://electron-vite.org/guide/#configuring-electron-vite
Getting Started | electron-vite
Next generation Electron build tooling based on Vite.
Ok thank you so much man!