Closed hexadecible closed 4 years ago
Interesting, it looks like the trouble is coming from the sodium-native module. Could you double check what the requirements are for that and that your setup meets them? It could be that the version of electron you're using isn't compatible with them.
I got it working in electron@7.1.4 with electron-react-boilerplate@0.18.1
One caveat is that you should be running the dat-sdk inside the main thread rather than within a browser window for the best results. I combine that with electron's remote
API and a wrapper over the main dat interactions. (sadly this project isn't open source yet)
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'
});
}
I just ran into this too, I went with the approach of making a rebuild.sh
script in the root of my project (not using electron starter for this).
https://www.electronjs.org/docs/tutorial/using-native-node-modules#using-npm
Unsure if you already know this but just to make it clear: all native modules used by hyper* have prebuilds bundled for electron, so do not rebuild any of those :)
@mafintosh What should I be doing about the prebuilds not working with a regular npm install
?
@RangerMauve open an issue on the relevant native repo. any latest major is supported through n-api on node 10+, recent electrons
I'm having a bunch of other issues, but adding "npmRebuild": false,
to my package.json helped. 🤷
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