OpenGSN v2.2.1 cannot be built for Electron

@opengsn/provider (v2.2.1) cannot be installed in an Electron app due to issues with native dependencies related to secp256k1. These issues do not occur when @opengsn/gsn (v2.1.0) is used instead.

Repro Steps:

  1. Set up an electron app with Webpack. You can clone Electron React Boilerplate to get started quickly.

  2. yarn add @opengsn/provider - you’ll get a warning that this is a native dependency. This does not occur with yarn add @opengsn/gsn, which installs just fine.

  3. Follow the instructions and move the dependency over to the inner package.json and attempt to yarn add @opengsn/provider again. You’ll see the following error message:

✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/Users/varun/src/electron-react-boilerplate/src/node_modules/secp256k1'.
Error: `make` failed with exit code: 2

Error: node-gyp failed to rebuild '/Users/varun/src/electron-react-boilerplate/src/node_modules/secp256k1'.
Error: `make` failed with exit code: 2

    at ModuleRebuilder.rebuildNodeGypModule (/Users/varun/src/electron-react-boilerplate/node_modules/electron-rebuild/lib/src/module-rebuilder.js:193:19)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async Rebuilder.rebuildModuleAt (/Users/varun/src/electron-react-boilerplate/node_modules/electron-rebuild/lib/src/rebuild.js:183:9)
    at async Promise.all (index 231)
    at async Rebuilder.rebuild (/Users/varun/src/electron-react-boilerplate/node_modules/electron-rebuild/lib/src/rebuild.js:141:13)
    at async /Users/varun/src/electron-react-boilerplate/node_modules/electron-rebuild/lib/src/cli.js:145:9
    throw err;

Error: Command failed: ../node_modules/.bin/electron-rebuild --parallel --force --types prod,dev,optional --module-dir .
    at checkExecSyncError (node:child_process:636:11)
    at execSync (node:child_process:672:15)
    at Object.<anonymous> (/Users/varun/src/electron-react-boilerplate/.erb/scripts/ElectronRebuild.js:18:3)
    at Module._compile (node:internal/modules/cjs/loader:1083:30)
    at Module._compile (/Users/varun/src/electron-react-boilerplate/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Object.newLoader [as .js] (/Users/varun/src/electron-react-boilerplate/node_modules/pirates/lib/index.js:104:7)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12) {
  status: 255,
  signal: null,
  output: [ null, null, null ],
  pid: 7279,
  stdout: null,
  stderr: null

Additional Notes:

  1. Running cs src && yarn add secp256k1 works just fine when done as a native dependency. It’s only when doing it with @opengsn that the failure happens.

  2. I noticed that in the yarn.lock, the dependencies on secp256k1 changed slightly between the versions. The previous version listed both 3.x and 4.x while the new version only includes 4.x.

I’ve cross posted it to the secp256k1 repo here: node-gyp issue · Issue #178 · cryptocoinjs/secp256k1-node · GitHub

I think the issue is that opengsn/gsn is still on version 2.1.0 on npm


I really not sure what your problem is:
I just cloned this boilerplate repo and added "@opengsn/provider" to it. with no problem.

Note that metamask doesn’t work within electron.
so instead of the injected window.ethereum you need to use an rpc provider (e.g. web3-providers-http).
It should also be able to use a browser provider such as “portis”.

Thanks for attempting this @drortirosh.

The problem seems to be building the native dependencies, and it fails during the yarn install step, so this is way before even calling window.ethereum or using the package. I also verified that I’m able to install the failing deps (secp256k1 and keccack) when added directly. I’ve also attempted to clear ~/.node_gyp, node_modules, reinstall xcode tools and all the other common steps that cause make issues.

My best summary of the issue: installing @opengsn/provider fails while trying to make secp256k1 and keccak as part of the installation process on my system.

I’m currently using:

Electron v11,
Node: v14, v15 (tested on both)
OS X: Big Sur

What version were you able to add @opengsn/provider on successfully? And did you add it to the package.json or the src/package.json file?