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

zmq.node is not a valid Win32 Application Error using Electron #302

Closed
masonctaylor opened this issue Feb 7, 2019 · 11 comments
Closed

zmq.node is not a valid Win32 Application Error using Electron #302

masonctaylor opened this issue Feb 7, 2019 · 11 comments

Comments

@masonctaylor
Copy link

Hi! So I am trying to create a (very) simple Electron app with (very) simple zeromq functionality, but am getting an error thrown from my require('zeromq') statement. My error seems to be similar to #242 , which was fixed by a prebuild-install update, but I'm still having this issue.

Steps to Repro

  1. Clone electron-quick-start
  2. Run npm install
  3. Run npm install zeromq
  4. Run npm rebuild zeromq --runtime=electron --target=4.0.3
  5. Add var zmq = require("zeromq"); to main.js
  6. Run npm start

Versions

  • Electron 4.0.3
  • Node 10.11.0
  • zeromq 5.1.0

Error message

App threw an error during load Error: \\?\C:\src\electron-quick-start\node_modules\zeromq\build\Release\zmq.node is not a valid Win32 application. \\?\C:\src\electron-quick-start\node_modules\zeromq\build\Release\zmq.node at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31) at Object.Module._extensions..node (internal/modules/cjs/loader.js:722:18) at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31) at Module.load (internal/modules/cjs/loader.js:602:32) at tryModuleLoad (internal/modules/cjs/loader.js:541:12) at Function.Module._load (internal/modules/cjs/loader.js:533:3) at Module.require (internal/modules/cjs/loader.js:640:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (C:\src\electron-quick-start\node_modules\zeromq\lib\index.js:6:11) at Object.<anonymous> (C:\src\electron-quick-start\node_modules\zeromq\lib\index.js:857:3)

@koszonetdoktor
Copy link

If you check this file:
https://github.com/zeromq/zeromq.js/blob/master/.travis.yml
It seems like one of the env parameters has the value of ELECTRON="3.0.0".
I am not a travis expert and I have no clue, what does that mean really, but I think that's why you can't rebuild it to Electron 4.
I am using zmq with Electron 3, and I can't go to higher version of Electron, probalby becasue of that.
It would be nice, if someone much smarter than I am, could provide a fix or workaround for that issue.

@dwasyluk
Copy link

Any updates on this? I'm using electron 5 and having this same issue when trying to run the app on windows. I tried npm rebuild zeromq --runtime=electron --target=5.0.0 and it had no effect.

@crifan
Copy link

crifan commented Jan 20, 2020

seems same error, please see my answer in this post A dynamic link library (DLL) initialization routine failed

solution is:

Change
node\_modules\\zerorpc\\node\_modules\\zeromq\\lib\\index.js
from

var EventEmitter = require('events').EventEmitter
  , zmq = require('../build/Release/zmq.node')
  , util = require('util');

to:

var EventEmitter = require('events').EventEmitter

let path = require('path')
let zmqNodePath = path.join("..", "build", "Release", "zmq.node")
var zmq = require(zmqNodePath)

var util = require('util')

@mccauleyp
Copy link

mccauleyp commented Nov 16, 2023

I'm seeing this error to when trying with "zeromq": "6.0.0-beta.17" and "electron": "27.0.2". I followed instructions in this comment (#384 (comment)) to get the build to succeed using electron-forge, but then I hit the "not a valid Win32" error at runtime. I'm a at loss now, if anyone has any guidance that'd be great! The above comment doesn't seem to apply to the latest version anymore, and I'm seeing other issues when downgrading.

@aminya
Copy link
Member

aminya commented Nov 16, 2023

@mccauleyp Did you try with the prebuilds?

@mccauleyp
Copy link

mccauleyp commented Nov 16, 2023

@mccauleyp Did you try with the prebuilds?

@aminya, thanks for your question!

Apologies, not 100% sure. I thought that simply doing npm install [email protected] would use the prebuilt binaries if they were available. Do you mean something different than that? For context, I'm running this in a GitHub Action on ubuntu-latest, so building on Linux for Windows. My forge/webpack configs look almost exactly like this one (#384 (comment)), except in webpack.main.config.ts, I have:

  externals: {
    zeromq: "zeromq",
  },

(i.e. zeromq instead of zeropc), and in forge.config.ts the hooks are modified slightly from the linked example to be:

  hooks: {
    packageAfterCopy: async (
      _forgeOptions,
      buildPath,
      _electronVersion,
      _platform,
      _arch,
    ) => {
      await runNpmCmd(
        "Installing zeromq to packaged application...",
        `npm install zeromq@${packageInfo.dependencies.zeromq}`,
        buildPath,
      );
    },
  },

@aminya
Copy link
Member

aminya commented Nov 16, 2023

I am not sure if cross-compiling for Windows from Linux is supported. The prebuilds will be automatically selected, but it seems your cross-compiling setup makes it not work. Try using windows-latest

@mccauleyp
Copy link

mccauleyp commented Nov 16, 2023

I am not sure if cross-compiling for Windows from Linux is supported. The prebuilds will be automatically selected, but it seems your cross-compiling setup makes it not work. Try using windows-latest

@aminya, Thanks for your suggestion! I've switched the GitHub Action to use windows-latest. The pre-built binary installs as expected outside of the electron-forge build process, which is enough to run my unit tests, but the npm install zeromq inside the packageAfterCopy hook inside forge.config.ts doesn't seem to pull the prebuild and instead tries building from source. That build fails, and I'm trying to debug that now. If I remove the packageAfterCopy hook entirely, the build succeeds, but I get the same Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=118 uv=1 libc=glibc node=18.17.1 electron=27.0.2 webpack=true that discussed here: #384.

electron-forge automatically runs electron-rebuild, so that might be why the build is getting triggers inside the Electron build even though it might not be necessary...

@mccauleyp
Copy link

electron-forge automatically runs electron-rebuild, so that might be why the build is getting triggers inside the Electron build even though it might not be necessary...

Aha, this was the problem! The forge.config.ts config above was fetching the prebuild, but then electron-rebuild was trying to rebuild it and that build was failing. I disabled the rebuild by adding the following to forge.config.ts:

  rebuildConfig: {
    onlyModules: [" "]
  },

That just ensures that it doesn't try to rebuild anything. There's probably a better way to target just zeromq, but right now zeromq is the only thing I have that might need to be rebuilt, so this works for me.

I'm not sure why the rebuild is failing. I'm getting C compiler errors in the GitHub Action there. I tried taking some inspiration from your PR (#522) by adding aminya/setup-cpp@v1 to the workflow, but that didn't do the trick. I don't really need to chase that down, though, so I'll just move forward with disabling the automatic rebuild.

Thanks very much for your input, @aminya !!!

@aminya
Copy link
Member

aminya commented Nov 17, 2023

You're welcome! Glad that it worked. It would be great if you can document your findings and make a merge request in case others run into the same issue,

@aminya
Copy link
Member

aminya commented Aug 13, 2024

v6 was released. Please try again with the latest version, and report back if the issue still persists.
https://github.com/zeromq/zeromq.js/releases/tag/v6.0.0

@aminya aminya added the wontfix label Sep 16, 2024
@aminya aminya closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants