I'm using ExcelJS to read an Excel file ,the code is working fine in the local machine and even when I use the serverless invoke local command, but when deployed on lambda it is not working. The error I'm getting could be found on the attached image. Below is my code please help:
async function readExcel(fileUrl) {
try {
console.log(fileUrl);
const response = await axios.get(fileUrl, { responseType: 'arraybuffer' });
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(response.data);
const data = [];
const worksheet = workbook.getWorksheet(1);
worksheet.eachRow((row, rowNumber) => {
// Assuming each row contains data in a specific format (adjust as needed)
const rowData = {
LeadName: row.getCell(1).value,
MobileNumber: row.getCell(2).value,
Email:row.getCell(3).text,
VehicleRegistrationNumber: row.getCell(4).value,
City:row.getCell(5).value,
City_Id: row.getCell(6).value,
Comments: row.getCell(7).value,
VehicleModel: row.getCell(8).value,
AgeGroup:row.getCell(9).value,
Gender:row.getCell(10).value,
Destination:row.getCell(11).value,
Medium:row.getCell(12).value,
Campaign:row.getCell(13).value,
LeadSource :row.getCell(14).value
};
data.push(rowData);
});
data.shift();
return data;
} catch (error) {
console.error('Error reading Excel file:', error);
throw error;
}
}
I tried to change the code logged data it is there data is coming in response.data I'm expecting the code to run and return the data array.