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

Build hangs when rebuilding native when using npx only #6411

Open
mifi opened this issue Nov 11, 2021 · 28 comments
Open

Build hangs when rebuilding native when using npx only #6411

mifi opened this issue Nov 11, 2021 · 28 comments

Comments

@mifi
Copy link
Contributor

mifi commented Nov 11, 2021

  • Electron-Builder Version: 22.13.1
  • Node Version: 16.13.0
  • Electron Version: 8.5.5
  • Electron Type (current, beta, nightly): current
  • Target: darwin
npx electron-builder --mac

  • electron-builder  version=22.14.6 os=20.6.0
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  preset=react-cra
  • writing effective config  file=dist/builder-effective-config.yaml
  • rebuilding native dependencies  dependencies=drivelist@9.2.4 platform=darwin arch=x64
  • install prebuilt binary  name=drivelist version=9.2.4 platform=darwin arch=x64 napi=
  • build native dependency from sources  name=drivelist
                                          version=9.2.4
                                          platform=darwin
                                          arch=x64
                                          napi=
                                          reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
                                          error=prebuild-install info begin Prebuild-install version 5.3.6
    prebuild-install WARN install prebuilt binaries enforced with --force!
    prebuild-install WARN install prebuilt binaries may be out of date!
    prebuild-install info looking for cached prebuild @ /Users/mifi/.npm/_prebuilds/fee87d-drivelist-v9.2.4-electron-v76-darwin-x64.tar.gz
    prebuild-install http request GET https://github.com/balena-io-modules/drivelist/releases/download/v9.2.4/drivelist-v9.2.4-electron-v76-darwin-x64.tar.gz
    prebuild-install http 404 https://github.com/balena-io-modules/drivelist/releases/download/v9.2.4/drivelist-v9.2.4-electron-v76-darwin-x64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=8.5.5 runtime=electron arch=x64 libc= platform=darwin)

...then the command hangs and never returns.

When restarting the build with DEBUG we can see this printed:

  • execute command  command=/node-v16.13.0-darwin-x64/bin/node /node-v16.13.0-darwin-x64/lib/node_modules/npm/bin/npx-cli.js rebuild --verbose drivelist@9.2.4
                     workingDirectory=
  ⨯ cannot execute  cause=exit status 1
                    out=You forgot to tell me what to run when the files changes!

                    command=/node-v16.13.0-darwin-x64/bin/node /node-v16.13.0-darwin-x64/lib/node_modules/npm/bin/npx-cli.js rebuild --verbose drivelist@9.2.4
                    workingDir=
  • exited          command=app-builder_amd64 code=2 pid=62703

It's trying to run npx-cli.js of the module rebuild which I think is not what is intented. So something seems to be wrong with the code trying to run npm.

Instead running this command (without npx) yields a successful result:

./node_modules/electron-builder --mac
...
  • execute command  command=npm rebuild --verbose drivelist@9.2.4 workingDirectory=
  • command executed  executable=npm
                      out=rebuilt dependencies successfully
@mmaietta
Copy link
Collaborator

You can also try npm exec. electron-builder detects the package manager (yarn, npm) and uses it. Instead, npx is detected and IIRC native rebuilds end up being executed incorrectly

@mifi
Copy link
Contributor Author

mifi commented Nov 13, 2021

npm exec works! But in electron-builder npx is mentioned, so maybe this line should be changed to instead npm exec:

Since Node.js 8 [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) is bundled, so, you can simply use `npx electron-builder`.

anyways it would be nice if:

  1. electron-builder doesn't hang when that command fails, but instead spits out the actual error
  2. npx also works because I'm guessing many people are using npx still

this issue may be related to yarn workspaces btw (I get it when running inside a workspace subdir)

@stale
Copy link

stale bot commented Apr 16, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Apr 16, 2022
@mifi
Copy link
Contributor Author

mifi commented Apr 16, 2022

Still an issue with npx

@stale stale bot removed the backlog label Apr 16, 2022
@kyrofa
Copy link

kyrofa commented Apr 21, 2022

Just hit this today.

@Simon-Laux
Copy link
Contributor

I have this issue too since upgrading from npm 14 to 16

@RicoBrase
Copy link

Just encountered this today for myself.
Updated node vom v12 to v16 & npm dependencies from an old project from like 2019 or so and npx electron-builder would hang for me after checking for prebuilds on this command:

/usr/bin/node /usr/lib/node_modules/npm/bin/npx-cli.js rebuild --verbose <package1> <package2> <package3> workingDirectory=

Calling npm exec electron-builder wont hang here and will result in a successful build.


electron-builder: v23.0.3
node: v16.15.1
npm: v8.11.0

@amoscatelli
Copy link

"npm exec electron-builder" doesn't work on Windows and tries to open electron-builder.js in a file editor

@vladimiry
Copy link
Contributor

"npm exec electron-builder" doesn't work on Windows

npm exec --package=electron-builder -- electron-builder same?

@amoscatelli
Copy link

yes, that's the same, doens't change a thing

@vladimiry
Copy link
Contributor

vladimiry commented Aug 3, 2022

I don't run Windows, but I remember it worker well on GH CI Windows image/env.

yes, that's the same, doens't change a thing

npm -v (If I remember it right, exec got supported since npm v7)?

@amoscatelli
Copy link

I don't run Windows, but I remember it worker well on GH CI Windows image/env.

yes, that's the same, doens't change a thing

npm -v (If I remember it right, exec got supported since npm v7)?

8.15.0

I confirm running "npm exec --package=electron-builder -- electron-builder" opens electron-builder.js in my notepad++

@amoscatelli
Copy link

On windows I resorted to "./node-modules/.bin/electron-builder" to build using local installation

@RicoBrase
Copy link

Just encountered this today for myself. Updated node vom v12 to v16 & npm dependencies from an old project from like 2019 or so and npx electron-builder would hang for me after checking for prebuilds on this command:

/usr/bin/node /usr/lib/node_modules/npm/bin/npx-cli.js rebuild --verbose <package1> <package2> <package3> workingDirectory=

Calling npm exec electron-builder wont hang here and will result in a successful build.

electron-builder: v23.0.3 node: v16.15.1 npm: v8.11.0

I should add that I was trying to build on a Raspberry Pi running a linux distribution, since I needed a 32-bit ARM (armv7l) AppImage package.

@mmaietta
Copy link
Collaborator

I confirm running "npm exec --package=electron-builder -- electron-builder" opens electron-builder.js in my notepad++

This is a different issue and is expected behavior, not related to electron-builder. Node seems to search the current directory for any executable script named electron-builder, so it pulls up electron-builder.js in notebad. Simple solution, rename your file electron-builder-config.js and pass it in with --config arg

@qishibo
Copy link

qishibo commented Oct 15, 2022

node14 is ok but node16 encounters this error, while execing npx electron-builder xxx

so I use node_modules/.bin/electron-builder instead of npx, this worked for me
electron-builder: 8.5.0

@olimexsmart
Copy link

Same here:
This hangs at "install prebuilt binary" and needs Ctrl-C:

$ npx electron-builder build --win portable
  • electron-builder  version=23.6.0 os=10.0.19043
  • electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies

To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
  • writing effective config  file=dist\builder-effective-config.yaml
  • "electron-squirrel-startup" dependency is not required for NSIS
  • rebuilding native dependencies  dependencies=@serialport/bindings-cpp@10.7.0, better-sqlite3@7.6.2 platform=win32 arch=x64
  • install prebuilt binary  name=better-sqlite3 version=7.6.2 platform=win32 arch=x64 napi=
  • cancelled by SIGINT
  ⨯ D:\ProgettiLavoro\HURV\node_modules\app-builder-bin\win\x64\app-builder.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
3221225786  failedTask=build stackTrace=Error: D:\ProgettiLavoro\HURV\node_modules\app-builder-bin\win\x64\app-builder.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
3221225786
    at ChildProcess.<anonymous> (D:\ProgettiLavoro\HURV\node_modules\builder-util\src\util.ts:250:14)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at ChildProcess.cp.emit (D:\ProgettiLavoro\HURV\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

Instead this works fine:

$ ./node_modules/.bin/electron-builder build --win portable
  • electron-builder  version=23.6.0 os=10.0.19043
  • electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies

To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
  • writing effective config  file=dist\builder-effective-config.yaml
  • "electron-squirrel-startup" dependency is not required for NSIS
  • rebuilding native dependencies  dependencies=@serialport/bindings-cpp@10.7.0, better-sqlite3@7.6.2 platform=win32 arch=x64
  • install prebuilt binary  name=better-sqlite3 version=7.6.2 platform=win32 arch=x64 napi=
  • packaging       platform=win32 arch=x64 electron=17.4.11 appOutDir=dist\win-unpacked
  • default Electron icon is used  reason=application icon is not set
  • building        target=portable file=dist\hli-ram-view 1.0.0.exe archs=x64

BTW I'm on Windows 10 from VSCode terminal

@shahriar0247
Copy link

just got the thing too, stuck after using npx electron-builder, using npm exec gives me error, i had to install electron builder globally and then it works

@juliangruber
Copy link

Potentially related: #7090

@sergeushenecz
Copy link

sergeushenecz commented Apr 3, 2023

I have same issue if i use npm exec i have error on rebuild native dependecies. on node v14 work good after migrate on v16 i have error.

@Jazcash
Copy link

Jazcash commented Apr 19, 2023

Same issue here with better-sqlite3 package and any version of node above 14. Hangs indefinitely on install prebuilt binary (waited 4 hours then gave up). Only an issue in github action, works fine locally.

image

@juliangruber
Copy link

Try npm exec -- electron-builder instead of npx electron-builder

@wildone
Copy link

wildone commented May 15, 2023

This has started happening to me in Github Actions after upgrade to latest on all packages.

electron-builder: v23.6.0
node: v18.3.0
npm: v8.11.0

 execute command  command='C:\hostedtoolcache\windows\node\18.3.0\x64\node.exe' 'C:\hostedtoolcache\windows\node\18.3.0\x64\node_modules\npm\bin\npx-cli.js' rebuild --verbose bufferutil@4.0.6 utf-8-validate@5.0.9

Source: https://github.com/typerefinery-ai/typerefinery/actions/runs/4979950195/jobs/8912352154

Trying to install these packages globally.

@rotu
Copy link
Contributor

rotu commented Aug 18, 2023

Oh gosh. I just tripped across this issue after being frustrated by this issue for days without knowing what I was doing wrong. I'd love to see a fix!

@j0hnm4r5
Copy link

j0hnm4r5 commented Sep 2, 2023

I'm hitting this issue with GitHub Actions (using https://github.com/samuelmeuli/action-electron-builder). Locally, npm run dist (which is electron-builder) and npm exec electron-builder work fine, but npx electron-builder does not.

@juliangruber
Copy link

Have you tried npm exec -- electron-builder instead of npx electron-builder?

@rotu
Copy link
Contributor

rotu commented Sep 3, 2023

I think the root cause is npm/cli#6662 via https://github.com/develar/app-builder/blob/4e2aa6a12e2bc3d31ec0d01d661fb3a4d65248ff/pkg/node-modules/rebuild.go#L361-L366

@rotu
Copy link
Contributor

rotu commented Sep 9, 2023

Root cause npm/cli#6662 is now fixed in npm@10.1.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests