automation-stack / electron-sudo

Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.
MIT License
383 stars 55 forks source link

Error Uncaught Exception: TypeError: Sudoer is not a constructor #62

Open duongtungls opened 6 years ago

duongtungls commented 6 years ago

I use example code on Electron main thread but get back error Uncaught Exception: TypeError: Sudoer is not a constructor

const {Sudoer} = require('electron-sudo')

let options = {name: 'electron sudo application'},
    sudoer = new Sudoer(options);

/* Spawn subprocess behavior */
let cp = await sudoer.spawn(
  'echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}
);
cp.on('close', () => {
  /*
    cp.output.stdout (Buffer)
    cp.output.stderr (Buffer)
  */
});

Please help figure out where is problem. thanks

juleskreutzer commented 6 years ago

require('electron-sudo').default

XDGFX commented 2 years ago

I had to use

const Sudoer = require("electron-sudo").default

There was nothing to unpack when using const { Sudoer } = ...