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

Electron with [email protected] v5-compat fails as no native build was found #384

Closed
Crowdedlight opened this issue Feb 21, 2020 · 15 comments · Fixed by #522
Closed

Electron with [email protected] v5-compat fails as no native build was found #384

Crowdedlight opened this issue Feb 21, 2020 · 15 comments · Fixed by #522

Comments

@Crowdedlight
Copy link

Describe the bug
When using [email protected] v5-compat it does not work with electron but gives the error of:

No native build was found for platform=linux arch=x64 runtime=electron abi=73 uv=1 libc=glibc

The electron window launches, however this is output in the development console and the app just shows a white window.

I have tried to do the following to solve it, without luck:

  • Use electron-rebuild
  • Tried to manually build zeromq with target=6.0.0 with command: ../node-gyp/bin/node-gyp.js rebuild --target=6.0.0 --arch=x64 --dist-url=https://electronjs.org/headers

This is observed in my vue-electron project based on: https://github.com/nklayman/vue-cli-plugin-electron-builder
This error happens for both for development and building.

If I downgrade to zeromq v.5.1.1 as another issue suggested then the project correctly rebuilds and I can use it without any errors. However as the server uses zeromq v6.0.0 it appears that I cannot establish a connection with v.5.1.1.

I thought it might be an issue with the precompiled for the 6.0.0 versions, as v5.1.1 works? However I couldn't figure out how to see what node version the precompiled for v6.0.0 were compiled against.

I have another vue-electron project based on: https://github.com/SimulatedGREG/electron-vue where the development works with v6.0.0-beta.6, however as soon as I build and run the appimage it errors with the same error:

No native build was found for platform=linux arch=x64 runtime=electron abi=73 uv=1 libc=glibc

Reproducing

  • create new vue-electron project
  • add zeromq v.6.0.0
  • try and start the development server

My versions

  • OS: Ubuntu 18.04
  • ZeroMQ.js version: 6.0.0-beta.6
  • Node v12.13.0
  • yarn 1.21.1
  • electron ^6.0.0 (Same result with electron ^7.0.0)
@mzy2240
Copy link

mzy2240 commented Apr 23, 2020

Have the same problem here.

@GuillaumeSchmid
Copy link

It seems that it is because the prebuilt binaries are not properly installed when compiled in an electron context.
The workaround I found is:
cd node_modules/electron/dist
ln -s ../../zeromq/prebuilds .
And it builds and run.
I have not packaged yet, I don't know it it works.

I use Electron 9.0.3 on Ubuntu 20.04 with zeromq 6.0.0-beta6 with typescript and webpack.

@rolftimmermans
Copy link
Member

Thanks for the feedback. I'd love to get this resolved because ZeroMQ is popular with Electron-based apps. However I'm not familiar with Electron at all.

So I'm looking for:

  1. people that can propose fixes for the published packages, test them and perhaps improve the CI infrastructure for Electron, or
  2. people that can explain to me how to setup a basic Electron-based example so I can make improvements to the packages & test it directly

@GuillaumeSchmid
Copy link

I don't know node/electron well enough to help you on the first point, sorry...
I work on my first project and I am discovering all that.
On the second point, here is a very simple way to build a test project:

yarn create electron-app zeromqtest --template=typescript-webpack
then "yarn star"t works.

Inside the src/main.ts, just add
import {Pair} from "zeromq"
var s = new Pair()

at the top of the file and then you should have the problem:

Error: No native build was found for platform=linux arch=x64 runtime=electron abi=80 uv=1 libc=glibc
at Function.module.exports../node_modules/node-gyp-build/index.js.load.path
...
...

You can fix it with the symbolic link workaround.

@GuillaumeSchmid
Copy link

I may have a fix.
The solution with the symbolic link will not work when packaging because zeromq is recompiled and the prebuilds is not linked automatically.

I added the following to the file webpack.main.config.js:
node: {
__dirname: true
},

And now, it packages correctly, there is no need for the link any more.

@Letrab
Copy link

Letrab commented Jun 30, 2020

@Bzerk-Seven : Does it also works for you with a bundled/packaged application (with electron-packager / electron-builder / ...)?

Did you expose zeromq as webpack external? Any other thing?
My prod build works, but my packaged app does not resolves the zeromq lib.

@GuillaumeSchmid
Copy link

I did not do anything more config than adding the 3 lines. I am not very familiar with webpack and even node/electron, so I don't know what is a webpack external.
I just added zeromq with yarn and this 3 lines config and could make the test app run.

@monstarnn
Copy link

@Bzerk-Seven thanks for your solution, it helps me on macos 10.15.7, zeromq 6.0.0-beta.6, node 12.18.4, electron 6.1.12

@raychengy
Copy link

@Letrab It took me days, but I got a workaround. If you're still having an issue with the packaged app using the electron-forge webpack template, I had to mark zerorpc (depends on zeromq) in webpack.config.externals.

In webpack.main.config.js:

module.exports = {
  entry: './src/main.js',
  externals: {
    zerorpc: 'zerorpc'
  },
  mode: "development",
  // Put your normal webpack config below here
  module: {
    rules: require('./webpack.rules'),
  },
};

And in forge.config.js, I had added a function to run npm install in the packageAfterCopy hook:

const { exec } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const ora = require('ora');
const fs = require('fs-extra');

const runNpmCmd = (msg, npmCmd, cwd) => {
    const spinner = ora(msg).start();
    return promisify(exec)(
        npmCmd,
        { cwd }
    ).then(() => spinner.succeed());
};

module.exports = {
    "packagerConfig": {},
    "makers": [
        {
            "name": "@electron-forge/maker-squirrel",
            "config": {
                "name": "electron_app"
            }
        },
        {
            "name": "@electron-forge/maker-zip",
            "platforms": [
                "darwin"
            ]
        },
        {
            "name": "@electron-forge/maker-deb",
            "config": {}
        },
        {
            "name": "@electron-forge/maker-rpm",
            "config": {}
        }
    ],
    "plugins": [
        [
            "@electron-forge/plugin-webpack",
            {
                "mainConfig": "./webpack.main.config.js",
                "renderer": {
                    "config": "./webpack.renderer.config.js",
                    "entryPoints": [
                        {
                            "html": "./src/index.html",
                            "js": "./src/renderer.js",
                            "name": "main_window"
                        }
                    ]
                }
            }
        ]
    ],
    "hooks": {
        "packageAfterCopy": async (_forgeOptions, buildPath, _electronVersion, _platform, _arch) => {
            await runNpmCmd(
                "Installing zerorpc npm package to Package Application",
                'npm install git+ssh://[email protected]:hokiedsp/zerorpc-node.git -S',
                buildPath,
            );
        }
    }
}

Depending on the node-version you're using, you might want to install electron-rebuild and rebuild the native node modules in the packageAfterCopy hook as well. I'd ended up installing a node version that matches the one used with the electron version.

@Letrab
Copy link

Letrab commented Dec 11, 2020

@raychengy Thanks for the tip. In the meanwhile I switched to electron-webpack, which has been great for me. Takes care of (most of) webpack config and handles electron-rebuild dependencies very well!

So if anything I can recommend to anyone, use electron-webpack!

@Bilb
Copy link

Bilb commented Mar 11, 2021

node: {
__dirname: true
},

This does not work for me.
My app runs fine if I don't make the zmq calls I have on the electron-main process. But if I uncomment the code importing zmq, I get the No native library found error.

If I try to set the __dirname field to true as you suggest, nothing load on the app and I get an error saying that index.html was not found.

@eric-burel
Copy link

eric-burel commented Jan 4, 2022

Using externals as @raychengy is the way to go, and seems to work out of the box in Electron React Boilerplate.
You need to set it up both in your Webpack dev config and prod config for the main process.

I don't use forge so I didn't have to set anything else.

Starting from Electron 12 (Node 14), I need to run "electron-rebuild" though after install, not sure why: https://github.com/electron/electron-rebuild

At the moment I'll stay with Electron 11 and Node 12

@ktavabi
Copy link

ktavabi commented Apr 21, 2022

I am encountering similar issue on macOS 12.3.1 M1

Uncaught Error: No native build was found for platform=darwin arch=x64 runtime=electron abi=85 uv=1 libc=glibc node=12.18.3 electron=11.5.0 loaded from: ~/.atom/packages/Hydrogen/node_modules/@aminya/zeromq

@GRamosPlux
Copy link

GRamosPlux commented Mar 23, 2023

Using externals as @raychengy is the way to go, and seems to work out of the box in Electron React Boilerplate. You need to set it up both in your Webpack dev config and prod config for the main process.

I don't use forge so I didn't have to set anything else.

Starting from Electron 12 (Node 14), I need to run "electron-rebuild" though after install, not sure why: https://github.com/electron/electron-rebuild

At the moment I'll stay with Electron 11 and Node 12

Hello to everyone!

Indeed, I totally agree, @raychengy solution was perfect.
Thank you very much for your valuable help!

However, in my particular case, it was necessary to also include zeromq as an external (in addition to/instead of zerorpc) 😊

@dawadam
Copy link

dawadam commented Jan 1, 2024

I have the same problem with the electron 28 with the "@electron-forge/cli" using "vite".
zeromq is the latest version : 6.0.0-beta.19

Error: No native version found for platform=linux arch=x64 runtime=electron abi=119 uv=1 libc=glibc node=18.18.2 electronic=28.1.0

An error occurs when you simply add a line using zmq, like this: const pullSocket = new zmq.Pull()

I can't use Webpack trick because no Webpack, I use "vite".

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