Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when packing for Linux and Windows from a macOS #484

Open
msbrogli opened this issue Jan 12, 2024 · 2 comments
Open

Error when packing for Linux and Windows from a macOS #484

msbrogli opened this issue Jan 12, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@msbrogli
Copy link
Member

msbrogli commented Jan 12, 2024

Summary

The following error is happening on Linux:

image

And the following error is happening on Windows:

[Window Title]
Error

[Main Instruction]
A JavaScript error occurred in the main process

[Content]
Uncaught Exception:
Error: \\?\C:\Users\Tulio\AppData\Local\Temp\43c7bae1-4b77-45c3-817c-da7016b3c4d0.tmp.node is not a valid Win32 application.
\\?\C:\Users\Tulio\AppData\Local\Temp\43c7bae1-4b77-45c3-817c-da7016b3c4d0.tmp.node
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:2131)
    at Object.<anonymous> (node:internal/modules/cjs/loader:1356:18)
    at Object.func [as .node] (node:electron/js2c/asar_bundle:2:2358)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at node:internal/modules/cjs/loader:967:12
    at Function._load (node:electron/js2c/asar_bundle:2:13327)
    at Module.require (node:internal/modules/cjs/loader:1150:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at load (C:\Users\Tulio\AppData\Local\Programs\hathor-wallet\resources\app.asar\node_modules\usb\node_modules\node-gyp-build\node-gyp-build.js:22:10)
    at Object.<anonymous> (C:\Users\Tulio\AppData\Local\Programs\hathor-wallet\resources\app.asar\node_modules\usb\dist\usb\bindings.js:8:36)

[OK]

Root Cause Analysis

Why are these errors happening?

Because their packages are loading an invalid executable. Specifically, they are loading a Mach-O executable generated by the usb package which was supposed to be used only in a macOS.

Why?

Because the usb package uses the node-gyp-build package to load the shared object. As the usb package has a build/ folder, it supersedes the prebuilt binaries in the prebuilds/ folder (which contains binaries for all platforms) and the wrong object is loaded.

Why?

Because node-hid cannot load a prebuilt binary so it launches a rebuild which is also rebuilding the usb package using the node-gyp rebuild. But this rebuilding tool does not recognize prebuilt binaries so it actually builds the usb package and creates the build/ folder.

Why?

(pending)

Notes

Quick fix

Here is one quick fix. It works because the removal of this file prevents the usb package from building.

diff --git a/release.sh b/release.sh
index fc1e338..14c5ef2 100755
--- a/release.sh
+++ b/release.sh
@@ -31,6 +31,8 @@ step3() {
        echo "step3: (empty)"
        #echo step3: install missing packing tools
        #npm install electron-builder@latest
+
+       rm ./node_modules/usb/binding.gyp
 }

 step4() {

@r4mmer is experimenting using the overrides in package.json to change the dependency of a dependency. But it is still not working.

@msbrogli msbrogli added the bug Something isn't working label Jan 12, 2024
@tuliomir
Copy link
Collaborator

All builds I've tested so far on #425 indicate that NodeJS 20 is able to adequately package the binaries to Linux.

The tests on Windows are still ongoing, but I believe this is a viable alternate solution to this issue.

@pedroferreira1
Copy link
Member

@r4mmer is experimenting using the overrides in package.json to change the dependency of a dependency. But it is still not working.

We already use the package patch-package, that has a simple way to change dependencies code. (https://github.com/ds300/patch-package#readme)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

4 participants