Electron-packager: can not locate local db file after packing

断了今生、忘了曾经 提交于 2019-12-04 14:53:19

When running the .exe, the current directory might be different so the relative path will not be correct. As you figured out you need to put together a full path, but rather than process.resourcesPath you should use app.getAppPath().

let dbFile = path.join(app.getAppPath(), 'app', 'db', 'example.db')

This should be give the correct path to the database file. An additional problem you may face is that the .exe will typically be packaged with the Asar format, which gives read access but not write access. So if you need to write to the database, it may be better to place it elsewhere. There are a number of paths provided by the electron.app.getPath(name) API, so for example you could use app.getPath("userData") to get the path provided for per-user application data. In this case your application would have to create the database file at that location.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!