electron/fuses

pathToElectron.endsWith is not a function

alex-drocks opened this issue · 4 comments

I read the Electron doscs + the README file in @electron/fuses.

First time I try to ue the Fuses so I assumed the example shown in the readme is code within the main process file.

Problem: it throws exception and I cannot use the fuses.

// main.js
'use strict';
console.time('init');

if (require('electron-squirrel-startup')) {
    //https://www.electronforge.io/config/makers/squirrel.windows#my-app-is-launching-multiple-times-during-install
    return;
}

(async () => {
    const {flipFuses, FuseVersion, FuseV1Options} = require('@electron/fuses');

    await flipFuses(
        require('electron'), // Returns the path to the electron binary
        {
            version: FuseVersion.V1,
            [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false, // Disables the NODE_OPTIONS environment variable
            [FuseV1Options.EnableNodeCliInspectArguments]: false, // Disables the --inspect and --inspect-brk family of ClI options
            [FuseV1Options.OnlyLoadAppFromAsar]: true // Enforces that Electron will only load your app from "app.asar" instead of it's normall search paths
        }
    );
})();

console.timeEnd('init');

Error log: `
init: 38.898ms

(node:4524) UnhandledPromiseRejectionWarning: TypeError: pathToElectron.endsWith is not a function
at pathToFuseFile (C:\Users\Alex\localdev\finance-d-electron\node_modules@electron\fuses\dist\index.js:48:24)
at setFuseWire (C:\Users\Alex\localdev\finance-d-electron\node_modules@electron\fuses\dist\index.js:57:26)
at exports.flipFuses (C:\Users\Alex\localdev\finance-d-electron\node_modules@electron\fuses\dist\index.js:108:19)
at C:\Users\Alex\localdev\finance-d-electron\src\main\main.js:12:11
at Object. (C:\Users\Alex\localdev\finance-d-electron\src\main\main.js:21:3)
at Module._compile (node:internal/modules/cjs/loader:1116:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
(Use electron --trace-warnings ... to show where the warning was created)
(node:4524) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on
unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
`

How are we meant to use this?
Could you please provide just a little more context around where and when to use the fuses properly?
I don't think I am getting this right.

Thank you very much in advance

Yes! I definitely assumed this too. What I think the intention is, is that you are supposed to set the fuses on the binary after it has been built (or maybe after you have installed Electron? I'm not sure). I think the example in the README is supposed to be in a separate file that gets executed at the end of the build process. The README should be more clear about this.
Can somebody please verify that this is correct?

Haven't tested yet, but looks like correct usage: electron-userland/electron-builder#6365 (comment)

@slapbox is correct, this script should be run during your packaging process. Not at runtime

🎉 This issue has been resolved in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀