In my electron renderer.js process, I am attempting to write to a CSV file. Unfortunately, most of the time, the writing process doesn't work as expected, and the addition of .then
is not executed. Despite this, no error messages or indications of mistakes are provided. Occasionally, the file is written successfully, but the confirmation message from .then
does not appear in the console. The inconsistency leaves me puzzled.
Interestingly, upon reloading the application with ctrl+r
after a failed attempt, the saving process reruns automatically (due to an onclick
attribute of a button calling a function containing the problematic code) and always works, including the .then
call.
Here's a snippet of my code:
var settings = [
["devtools", false, devtools, ""],
["language", "en", language, ""]
];
var csvWriter = window.createCsvWriter({
header: ['ABBREVIATION', 'DEFAULT', 'CUSTOM', ''],
path: 'saves/settings.csv'
});
csvWriter.writeRecords(settings)
.then(() => {
console.log('Saved successfully!');
});
The method window.createCsvWriter
is a preloaded script, while devtools
and language
are variables updated prior to this section of code execution.
Despite several successful runs, I am unable to pinpoint the source of the issues. Even debugging line by line yielded no useful insights. The settings array seems to be processed correctly, but the script gets stuck in loops and if-conditions related to the path handling.
An issue worth mentioning is that my code creates CSV files with commas at the end of rows, causing problems during importing later on. This will require further attention. If additional information is needed, please feel free to ask.
EDIT:
Upon scrutiny, I discovered that the code halts after the return __awaiter()
statement in
CsvWriter.prototype.writeRecords = function (records) {...}
. The records
array contains correct data for the CSV. Perhaps this detail could prove helpful.
EDIT2:
I attempted using fs.writeFile()
instead to address the issue, but encountered the same problem of an empty file without any errors. However, when reloading the page (where the code previously worked), multiple errors or confirmations were displayed for all attempts made in that session, indicating that the file was indeed written. It appears that something prevents the code from running completely until the page is reloaded. Could this be due to another global script interfering?
I do not have any breakpoints set in the code.