** Edit, I believe this is an issue with the initial boilerplate I started with (one using parcel) and is missing some part causing this issue. This seems to work just fine with electron-quick-start boilerplate **
I have searched around and can't find a solution. There is a youtube video tutorial showing how to read from the file system: https://www.youtube.com/watch?time_continue=292&v=PQZEymiWFh8
But I implement the same but get this error fs.readFile is not a function
. I am doing this in a react electron app however. Here is how I am setting this up:
const fs = require('fs');
const { dialog } = window.require('electron').remote;
...
getFile() {
dialog.showOpenDialog((fileNames) => {
// fileNames is an array that contains all the selected
if(fileNames === undefined){
console.log("No file selected");
return;
}
fs.readFile(fileNames[0], 'utf-8', (err, data) => {
if(err){
alert("An error ocurred reading the file :" + err.message);
return;
}
// Change how to handle the file content
console.log("The file content is : " + data);
});
});
}
It gets the file name, but fs.readFile
is throwing the not a function error. Anyone know a solution to this as it works in that tutorial video?