WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.26k stars 391 forks source link

How to install this library package for x64 architecture on ARM 64? #1096

Closed pnhuyduy closed 8 months ago

pnhuyduy commented 8 months ago

I'm using Mac m1 (arm64) and I want to build an Electron app for x64. Build process is fine, but when I open the app this error occurs.

image

I assume the problem is better_sqlite3.node is for arm64, not x64.

So like the title, can I install the packge for x64 or is there anyway to rebuild for it? Thanks!

neoxpert commented 8 months ago

This is not an issue of better-sqlite3 but your packaging process / build setup. What do you use for creating the package? Electron-builder, electron-forge or something else?

In order to create packages for another architecture, you should aim for using versions of Electron and libraries where prebuilt binaries exist to match the versions. Otherwise it is up to you to setup a proper toolchain for cross compiling. In the case of Electron I would recommend going for Electron v27 and better-sqlite3 9.0.0.

If you are using electron-builder and followed the instructions for building apps with native dependencies, it would be enough to adjust the build configuration for macos like

mac: {
  target: {
    target: 'dmg',
    arch: [
      'x64',
      'arm64'
    ]
  },
}

to create separate bundles for x64 and arch64 containing the proper native modules.

pnhuyduy commented 8 months ago

@neoxpert Thanks for your response! I solved this by command electron-builder install-app-deps --arch x64 to re-build the better-sqlite3 for x64.