在 electron 中集成了 sqlite3
使用的是 electron-builder 进行打包的
打包好了之后 打包应用就直接报错,去掉 sqlite3 模块打包的话 是没问题的
Uncaught Exception:
Error: dlopen(/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9, 0x0001): tried: '/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (code signature in <4B1D6A84-88AB-3BB3-BF26-DA71D77C9C6B> '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (no such file), '/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (code signature in <4B1D6A84-88AB-3BB3-BF26-DA71D77C9C6B> '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' not valid for use in process: library load disallowed by system policy), '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (code signature in <4B1D6A84-88AB-3BB3-BF26-DA71D77C9C6B> '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (no such file), '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' (code signature in <4B1D6A84-88AB-3BB3-BF26-DA71D77C9C6B> '/private/var/folders/p6/hxcfy6q57fq1_hrf30zydgxr0000gn/T/jingque.liketodo.com/.C8XU9Y66C5.jingque.liketodo.com.dPxlM9' not valid for use in process: library load disallowed by system policy)
at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138:18)
at Object.func [as .node] (electron/js2c/asar_bundle.js:5:2073)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/panghu/www/liketodo/front/dist_electron/mas-dev/Like To Do.app/Contents/Resources/app.asar/node_modules/sqlite3/lib/sqlite3-binding.js:4:17)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
我自己尝试过的方法:
1 、看了 electron 官方对 navtive module 打包的说明
https://www.electronjs.org/zh/docs/latest/tutorial/using-native-node-modules
按这个流程也操作了一遍 结果还是不行
2 、修改保存 database 的路径,还是不行
const sqlite3 = verbose();
// 获取应用程序的用户数据目录
const userDataPath = app.getPath('userData');
// 创建数据库文件保存路径
const dbPath = path.join(userDataPath, 'my-database.db');
// 创建 SQLite3 数据库连接
const db = new sqlite3.Database(dbPath, (error) => {
if (error) {
console.error('Failed to open database', error);
return;
}
有经验的大佬帮忙看看 如何解决
1
horizon 2023-08-04 10:57:40 +08:00
这个错误似乎是因为 Electron 在 Mac 平台对 SQLite 模块的限制导致的。
问下 chatGPT 吧,回答我就不贴上来了 |
2
woshipanghu OP @horizon 谢谢大佬 我先试试你说的方法
|