question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Electron build failing

See original GitHub issue

It looks like the SDK now officially supports Electron, but when I attempt to build the package I get the following errors. Is this the correct way to include the sdk into Electron, or are we supposed to build a browser bundle?

Electron React Boilerplate

✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@12.8.1 | darwin | x64
gyp info find Python using Python version 2.7.5 found at "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"
gyp info spawn /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/.electron-gyp/7.1.13/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/carolbaskins/.electron-gyp/7.1.13',
gyp info spawn args   '-Dnode_gyp_dir=/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/carolbaskins/.electron-gyp/7.1.13/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/sodium/binding.o
../binding.c:70:20: warning: implicit declaration of function 'napi_detach_arraybuffer' is invalid in C99 [-Wimplicit-function-declaration]
  SN_STATUS_THROWS(napi_detach_arraybuffer(env, array_buf), "failed to detach array buffer");
                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/sodium.node
clang: error: no such file or directory: '../lib/libsodium-x64.dylib'
make: *** [Release/sodium.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.4.0
gyp ERR! command "/Users/carolbaskins/.nvm/versions/node/v12.8.1/bin/node" "/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=7.1.13" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native
gyp ERR! node -v v12.8.1
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok 

Failed with exit code: 1

Error: gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@12.8.1 | darwin | x64
gyp info find Python using Python version 2.7.5 found at "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"
gyp info spawn /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/carolbaskins/.electron-gyp/7.1.13/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/carolbaskins/.electron-gyp/7.1.13',
gyp info spawn args   '-Dnode_gyp_dir=/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/carolbaskins/.electron-gyp/7.1.13/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/sodium/binding.o
../binding.c:70:20: warning: implicit declaration of function 'napi_detach_arraybuffer' is invalid in C99 [-Wimplicit-function-declaration]
  SN_STATUS_THROWS(napi_detach_arraybuffer(env, array_buf), "failed to detach array buffer");
                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/sodium.node
clang: error: no such file or directory: '../lib/libsodium-x64.dylib'
make: *** [Release/sodium.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.4.0
gyp ERR! command "/Users/carolbaskins/.nvm/versions/node/v12.8.1/bin/node" "/Users/carolbaskins/Documents/electron-mail-client/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=7.1.13" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /Users/carolbaskins/Documents/electron-mail-client/app/node_modules/sodium-native
gyp ERR! node -v v12.8.1
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok 

Failed with exit code: 1
    at SafeSubscriber._error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/spawn-rx/lib/src/index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:156:26)
    at Subscriber._error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:92:26)
    at Subscriber.error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:72:18)
    at SafeSubscriber._next (/Users/carolbaskins/Documents/electron-mail-client/node_modules/spawn-rx/lib/src/index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/Users/carolbaskins/Documents/electron-mail-client/node_modules/rxjs/internal/Subscriber.js:143:22)
child_process.js:660
    throw err;
    ^

Error: Command failed: ../node_modules/.bin/electron-rebuild --parallel --force --types prod,dev,optional --module-dir .
    at checkExecSyncError (child_process.js:621:11)
    at execSync (child_process.js:657:15)
    at Object.<anonymous> (/Users/carolbaskins/Documents/electron-mail-client/internals/scripts/ElectronRebuild.js:18:3)
    at Module._compile (internal/modules/cjs/loader.js:868:30)
    at Module._compile (/Users/carolbaskins/Documents/electron-mail-client/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:879:10)
    at Object.newLoader [as .js] (/Users/carolbaskins/Documents/electron-mail-client/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:731:32)
    at Function.Module._load (internal/modules/cjs/loader.js:644:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:931:10) {
  status: 255,
  signal: null,
  output: [ null, null, null ],
  pid: 52280,
  stdout: null,
  stderr: null
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mafintoshcommented, Jun 23, 2020

@RangerMauve open an issue on the relevant native repo. any latest major is supported through n-api on node 10+, recent electrons

1reaction
hexadeciblecommented, Jun 10, 2020

This ended up being an issue with electron-rebuild. It was attempting to rebuild sodium-native and should have been skipping over that module since it was already prebuilt. @mafintosh opened an issue a while back which was resolved, but it appears electron-rebuild is looking for

fs.exists(path.resolve(modulePath, 'prebuilds', `${process.platform}-${this.arch}`, `electron-${this.ABI}.node`))

It looks like this file no longer exists inside of sodium-native’s prebuild directory. I had to add the following as a workaround inside of internals/scripts/ElectronRebuild.js.

import path from 'path';
import { execSync } from 'child_process';
import fs, { readdirSync } from 'fs';
import { dependencies } from '../../app/package.json';

const nodeModulesPath = path.join(__dirname, '..', '..', 'app', 'node_modules');

const getModules = (source, exclude) =>
  readdirSync(source, { withFileTypes: true })
    .filter(dirent => dirent.isDirectory() && !exclude.includes(dirent.name))
    .map(dirent => dirent.name);

if (
  Object.keys(dependencies || {}).length > 0 &&
  fs.existsSync(nodeModulesPath)
) {
  // Skip modules that are already prebuilt
  const exclude = ['sodium-native', 'utp-native', '.bin'];
  const modules = getModules(nodeModulesPath, exclude);

  const electronRebuildCmd = `../node_modules/.bin/electron-rebuild --parallel --types prod,dev,optional --only ${modules.toString()} --module-dir .`;

  const cmd =
    process.platform === 'win32'
      ? electronRebuildCmd.replace(/\//g, '\\')
      : electronRebuildCmd;
  execSync(cmd, {
    cwd: path.join(__dirname, '..', '..', 'app'),
    stdio: 'inherit'
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Electron build failed - Stack Overflow
I am trying to learn Electron. Level - zero. I would check your node and electron versions match.
Read more >
Application entry file "build/electron.js" in the "<path>/dist/mac ...
I have tried adding "extends: null and also already had --em.main path to public/electron.js in package.json and my build still fails.
Read more >
Electron build for MacOS fails occasionally due to "self-signed ...
We are building a application for MacOS using Electron. Everything worked fine until last week, when our old Developer ID certificate expired.
Read more >
Code signing error on Windows Electron build
Code signing error on Windows Electron build ... Command failed: C:\Users\travis\AppData\Local\electron-builder\Cache\winCodeSign\ ...
Read more >
Build Instructions | Electron
Follow the guidelines below for building Electron itself, for the purposes of creating custom Electron binaries. For bundling and distributing your app code ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found