Error using a function that work in next13, any reason why?
Unanswered
Border Collie posted this in #help-forum
Border CollieOP
Hi, Im using a function to fetch data from .xlsx file (excel) .
Function is in page.tsx
// getExcel function
"xlsx": "^0.18.5"
"lodash": "^4.17.21",
get a undefined Promise in next14, but works fine in next13. Every code part is same. Why doesn't it work?
From next14:
from next13
Function is in page.tsx
import { join } from "path";
import { getExcel } from "../../utils/api/getExcel";
import fs from "fs";
export default async function Home() {
const filePath = join(process.cwd(), "something.xlsx");
const data = fs.existsSync(filePath) ? getExcel(filePath) : [];
console.log('data', data)// getExcel function
import * as XLSX from "xlsx";
import cloneDeep from "lodash/cloneDeep";
const CONST_FIRST_DAY_OF_YEAR = "2023-01-01";
export function getExcel(filePath) {
const workbook = XLSX.readFile(filePath);
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
let fileData = XLSX.utils.sheet_to_json(worksheet, {
header: excelHeader,
});
// remove all rows before 2023-01-01 in fileData
fileData = fileData.splice(5).filter((item) => {
const date = new Date(item.bokford);
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
if (date > yesterday) {
item.saldo = "LAST";
}
return date >= new Date(CONST_FIRST_DAY_OF_YEAR);
});
// Perform deep copy of fileData to eliminate non-serializable properties
return cloneDeep(fileData);
}"xlsx": "^0.18.5"
"lodash": "^4.17.21",
get a undefined Promise in next14, but works fine in next13. Every code part is same. Why doesn't it work?
From next14:
dataPromise {
undefined,
[Symbol(async_id_symbol)]: 2012743,
[Symbol(trigger_async_id_symbol)]: 2012686,
[Symbol(kResourceStore)]: BaseContext {
_currentContext: Map(4) {
Symbol(OpenTelemetry Context Key SPAN) => [Span],
...from next13
data [
{
bokford: '2024-10-10',
valuta: '2024-10-10',
nummer: '5484773329',
text: 'STORE BUTI/24-10-09',
belopp: -198,
},
...2 Replies
Border CollieOP
i get back: Error: Cannot access file D:\dev-personal-bank\jsm_banking\something.xlsx
Border CollieOP
solved it!