Common Next.js errorsReduce of empty array with no initial value
TypeError: Reduce of empty array with no initial value means array.reduce(fn) was called on an empty array without a starting value. With nothing to start from, JavaScript throws.
Why it happens in production
It works in development because your test data always has a few items. In production a filter returns nothing: an author with only one recipe, a customer with no orders yet, a search with no results.
How to fix it
Give reduce a starting value, or handle the empty case before you call it:
// Sums: start from 0.
const total = lines.reduce((sum, l) => sum + l.qty, 0);
// "Latest" or "biggest": there may be none.
const latest = others.length === 0 ? null : others.reduce((a, b) => (a.date > b.date ? a : b));
Then render the "none" case on purpose: hide that section, or say there's nothing yet.