尝试将大字符串写入文件时出现此错误。它至少已经工作了一次。但是随后我再次遇到以下错误。
它将向磁盘写入一个空文件。
有人知道如何解决此问题吗?
const csv = require("csvtojson");
var jsonexport = require('jsonexport');
const fs = require("fs").promises;
const saveJsonToCSV = jsonObj => {
jsonexport(jsonObj, function (err, csv) {
if (err) return console.log(err);
console.log("Length", csv.length); //Length 9866161
var path = appDir + "\\csv\\" +"test.csv"; //Path is valid
try {
fs.writeFilSync(path, csv);
console.log("Done writing:", result);
} catch (error) {
console.error(error);
}
});
return false;
}
TypeError: fs.writeFilSync is not a function
at C:\Users\jokar38\projects\sgcsv\tools\checkFile.js:32:16
at Parser.parse (C:\Users\jokar38\projects\sgcsv\node_modules\jsonexport\lib\parser\csv.js:34:38)
at module.exports (C:\Users\jokar38\projects\sgcsv\node_modules\jsonexport\lib\index.js:28:10)
at saveJsonToCSV (C:\Users\jokar38\projects\sgcsv\tools\checkFile.js:25:5)
at remove (C:\Users\jokar38\projects\sgcsv\tools\checkFile.js:101:21)
at csv.fromFile.then.jsonObj (C:\Users\jokar38\projects\sgcsv\tools\checkFile.js:61:29)
at Object.onfulfilled (C:\Users\jokar38\projects\sgcsv\node_modules\csvtojson\v2\Converter.js:111:33)
at Result.endProcess (C:\Users\jokar38\projects\sgcsv\node_modules\csvtojson\v2\Result.js:76:50)
at Converter.processEnd (C:\Users\jokar38\projects\sgcsv\node_modules\csvtojson\v2\Converter.js:178:21)
at C:\Users\jokar38\projects\sgcsv\node_modules\csvtojson\v2\Converter.js:171:19
at tryCatcher
(C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (C:\Users\jokar38\projects\sgcsv\node_modules\bluebird\js\release\async.js:138:12)
C:\Users\jokar38\projects\sgcsv\app.js:50
throw error;