Electron-dl returns undefined no matter what I do...
Closed this issue · 1 comments
LoganTann commented
Hello,
I installed this package and it doesn't work in my PC... Making a request will always return undefined
.
Tried to restart my computer, download a sample page, disabling every security stuff I made, nothing makes it work...
Dependencies : electron: ^9.2.1
, electron-dl: ^3.0.2
OS : Windows 10
sample code :
const electronDl = require('electron-dl');
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 300,
minHeight: 600,
icon: "favicon.ico",
webPreferences: {
nodeIntegration: true,
contextIsolation: false, //
enableRemoteModule: true, //
preload: path.join(__dirname, 'preload.js')
}
})
console.log(electronDl);
electronDl(mainWindow, "https://google.fr/").then(
r => console.log(r)
);
// ....
}
console output :
Logan@MSI ~/Documents/kagepro3_launcher (master)$ npm run start
> kagepro3_launcher@0.1.0 start C:\Users\Logan\Documents\kagepro3_launcher
> electron .
[Function] { download: [Function] }
(node:14028) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'then' of undefined
at createWindow (C:\Users\Logan\Documents\kagepro3_launcher\main.js:45:69)
at C:\Users\Logan\Documents\kagepro3_launcher\main.js:189:3
[....]
LoganTann commented
I solved the problem, by editing const electronDl = require('electron-dl');
to const {download} = require('electron-dl');
It's because electron-dl exports the download function as a part of an object ... Wow, hours spends for that beginner mistake 🤦 ...
https://stackoverflow.com/a/49828577