electron 打包遇到一个奇怪的问题

2023-08-04 10:24:52 +08:00
 woshipanghu

在 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;
      }

有经验的大佬帮忙看看 如何解决

535 次点击
所在节点    问与答
2 条回复
horizon
2023-08-04 10:57:40 +08:00
这个错误似乎是因为 Electron 在 Mac 平台对 SQLite 模块的限制导致的。

问下 chatGPT 吧,回答我就不贴上来了
woshipanghu
2023-08-04 12:52:53 +08:00
@horizon 谢谢大佬 我先试试你说的方法

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/962327

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX