webtorrent / webtorrent

⚡️ Streaming torrent client for the web

Home Page:https://webtorrent.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed to build in Electron with utp-native error

TechQuery opened this issue · comments

@webtorrent

What version of this package are you using?

2.2.1

What operating system, Node.js, and npm version?

  • OS: latest Mac OS & Ubuntu in GitHub actions
  • Node.js: 18.x
  • PNPM: 9.x

What happened?

When I run electron-forge make in GitHub actions with Mac OS, an error thrown:

✔ Copying files
› Traceback (most recent call last):
›   File "/Users/runner/work/client/client/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
›     import gyp  # noqa: E402
An unhandled rejection has occurred inside Forge:
›     ^^^^^^^^^^
Error: node-gyp failed to rebuild '/private/var/folders/3m/p59k4qdj0f17st0gn2cmj3640000gn/T/electron-packager/tmp-69fOMv/Electron.app/Contents/Resources/app/node_modules/utp-native'
at ChildProcess.<anonymous> (/Users/runner/work/client/client/node_modules/@electron/rebuild/lib/module-type/node-gyp/node-gyp.js:118:24)
›   File "/Users/runner/work/client/client/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
    at ChildProcess.emit (node:events:517:28)
›     import gyp.input
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
›   File "/Users/runner/work/client/client/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
›     from distutils.version import StrictVersion
› ModuleNotFoundError: No module named 'distutils'
› Error: `gyp` failed with exit code: 1
›     at ChildProcess.onCpExit (/Users/runner/work/client/client/node_modules/node-gyp/lib/configure.js:325:16)
›     at ChildProcess.emit (node:events:517:28)
›     at ChildProcess._handle.onexit (node:internal/child_process:292:12)
 ELIFECYCLE  Command failed with exit code 1.

then in Ubuntu, another error thrown:

✖ Making a rpm distributable for linux/x64 [FAILED: Command failed with a non-zero return code (1):
rpmbuild -bb /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/SPECS/xdgame_client.spec --target x86_64-none-linux --define _topdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64
Building target platforms: x86_64-none-linux
Building for target x86_64-none-linux
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EWLS85
RPM build errors:
+ umask 022
+ cd /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILD
+ /bin/rm -rf /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ /bin/mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT
+ /bin/mkdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ cp -r usr/bin usr/lib usr/share /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ /usr/lib/rpm/brp-compress /usr
+ /usr/lib/rpm/brp-elfperms
+ /usr/lib/rpm/brp-strip /usr/bin/strip
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare'
error: Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)
    Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)]
✖ Making distributables [FAILED: Command failed with a non-zero return code (1):
rpmbuild -bb /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/SPECS/xdgame_client.spec --target x86_64-none-linux --define _topdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64
Building target platforms: x86_64-none-linux
Building for target x86_64-none-linux
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EWLS85
RPM build errors:
+ umask 022
+ cd /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILD
+ /bin/rm -rf /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ /bin/mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT
+ /bin/mkdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ cp -r usr/bin usr/lib usr/share /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ /usr/lib/rpm/brp-compress /usr
+ /usr/lib/rpm/brp-elfperms
+ /usr/lib/rpm/brp-strip /usr/bin/strip
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare'
error: Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)
    Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)]
An unhandled rejection has occurred inside Forge:
Error: Command failed with a non-zero return code (1):
rpmbuild -bb /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/SPECS/xdgame_client.spec --target x86_64-none-linux --define _topdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64
Building target platforms: x86_64-none-linux
Building for target x86_64-none-linux
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EWLS85
RPM build errors:
+ umask 022
+ cd /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILD
+ /bin/rm -rf /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ /bin/mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT
+ /bin/mkdir /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64
+ mkdir -p /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ cp -r usr/bin usr/lib usr/share /tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/
+ /usr/lib/rpm/brp-compress /usr
+ /usr/lib/rpm/brp-elfperms
+ /usr/lib/rpm/brp-strip /usr/bin/strip
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare'
/usr/bin/strip: Unable to recognise the format of the input file `/tmp/electron-installer--2019-F5JUT6lnR0jU/xdgame_client_2.0.0.rc.5_x86_64/BUILDROOT/xdgame_client-2.0.0.rc.5-1.x86_64/usr/lib/xdgame_client/resources/app/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare'
error: Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)
    Bad exit status from /var/tmp/rpm-tmp.EWLS85 (%install)
at ChildProcess.<anonymous> (/home/runner/work/client/client/node_modules/electron-installer-redhat/node_modules/@malept/cross-spawn-promise/dist/src/index.js:99:24)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1098:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:517:28)
    at Socket.emit (node:domain:489:12)
    at Pipe.<anonymous> (node:net:350:12)
25h ELIFECYCLE  Command failed with exit code 1.

What did you expect to happen?

Building Electron & WebTorrent with no error.

Are you willing to submit a pull request to fix this bug?

No, I have no idea about how to fix this bug.

commented

you need to configure electron forge to exclude native dependencies

    "files": ["build/**/*", "!node_modules/**/*.{mk,a,o,h}"],
    "mac": {
      "singleArchFiles": "node_modules/+(register-scheme|utp-native|fs-native-extensions)/**",

is how you'd do it in electron builder, you need to find the equiv in forge

^ This approach is now broken due to blanket dependency on webrtc-polyfill which unconditionally pulls node-datachannel.

commented

it shouldn't, that approach enables native, doesn't disable it, so it does not matter if it's conditionally imported or not for this case? I think you're confused about something

commented

Sorry, this was meant as a update for original author to inform that he'll likely need to adjust singleArchFiles to include node-datachannel, despite Electron having its own support for WebRTC.

commented

yeah, electron is a special case because with nodeIntegration enabled it's both node.js and browser, you can also work around this by aliasing webrtc-polyfill to webrtc-polyfill/browser.js