V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
woshipanghu
V2EX  ›  问与答

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

  •  
  •   woshipanghu · 2023-08-04 10:24:52 +08:00 · 534 次点击
    这是一个创建于 469 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    horizon
        1
    horizon  
       2023-08-04 10:57:40 +08:00
    这个错误似乎是因为 Electron 在 Mac 平台对 SQLite 模块的限制导致的。

    问下 chatGPT 吧,回答我就不贴上来了
    woshipanghu
        2
    woshipanghu  
    OP
       2023-08-04 12:52:53 +08:00 via Android
    @horizon 谢谢大佬 我先试试你说的方法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5520 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:52 · PVG 14:52 · LAX 22:52 · JFK 01:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.