Getting below error while trying to read csv file in cypress. file is having data but some how xlsx plugin not able to read and convert to json file.
below is the code
const fs = require('fs');
const XLSX = require('xlsx');
const read = ({file, sheet}) => {
const buf = fs.readFileSync(file);
const workbook = XLSX.read(buf, { type: 'buffer' });
const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
return rows
}
and error is given below.
From Node.js Internals:TypeError: Cannot read property 'length' of undefinedat Object.sheet_add_json (D:\project\Shobhnaautomation\Internal-ProofOfConcept-BackOffice-Remedy-Web\node_modules\xlsx\xlsx.js:22252:52)at read (D:\project\Shobhnaautomation\Internal-ProofOfConcept-BackOffice-Remedy-Web\tests\e2e\plugins\Read-xlsx.js:8:26)at invoke (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\child\task.js:41:15)at (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\util.js:41:15)at tryCatcher (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\util.js:16:24)at Function.Promise.attempt.Promise.try (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\method.js:39:30)at Object.wrapChildPromise (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\util.js:40:24)at Object.wrap (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\child\task.js:47:9)at execute (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:142:13)at EventEmitter. (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:235:6)at EventEmitter.emit (events.js:210:6)at process. (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\lib\plugins\util.js:19:23)at process.emit (events.js:210:6)at process.emit (D:\Users\shobhnag\AppData\Local\Cypress\Cache\4.12.1\Cypress\resources\app\packages\server\node_modules\source-map-support\source-map-support.js:495:22)at emit (internal/child_process.js:876:13)at processTicksAndRejections (internal/process/task_queues.js:81:22)