m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
137 stars 27 forks source link

Error while signing windows .exe (electron-builder) #51

Closed tobiasmuecksch closed 1 year ago

tobiasmuecksch commented 1 year ago

Error Message

Failed

Unrecognized file type: /Users/tmuecksch/Sites/bico/v2/ehinger-app-v2/bico-app/electron/dist/win-unpacked/resources/app.asar.unpacked/node_modules/better-sqlite3-multiple-ciphers/build/Release/test_extension.node

Description

When I'm building my application with electron-builder for production; I also need to sign it (of course). This works perfectly fine for macOS. But it fails for windows.

To track this problem down, could you please explain to me what this file is for? Why is it called test_extension? Having test in it's name, seems to me as it shouldn't be there. better-sqlite3-multiple-ciphers/build/Release/test_extension.node

Screenshot

image

System Info

m4heshd commented 1 year ago

This is because you're trying to cross-build a native module.

While packaging, electron-builder automatically downloads the prebuilt binary for your target platform. If we didn't provide prebuilt binaries, your whole build process would fail. That download only contains the native library file better_sqlite3.node. What actually happens is it runs electron-builder install-app-deps under the hood and that process compiles the test_extension.node. It's only used for tests. It won't be created upon a typical installation.

All this means is that the test_extension.node is compiled for mac and better_sqlite3.node is compiled for the target platform. It's a complete mess. Yes, electron-builder can cross-compile but only when complex native modules aren't involved because electron-builder doesn't actually compile anything native. It's just a packager.

Moral of the story, never ever cross-build apps. Always use CI for that. Take a look at our build workflow. This issue is the same reason why we go through all this trouble to build prebuilt binaries.

tobiasmuecksch commented 1 year ago

@m4heshd Thank you for your in-depth answer. I will revise my build process accordingly.

willemdjong commented 1 year ago

https://github.com/electron-userland/electron-builder/issues/7652 this is the reason why!