TypeError: Object.groupBy is not a function

I am getting {TypeError: Object.groupBy is not a function} error after deploying the project to vercel.

It worked fine on my local.
Does vercel not support this now?

All configurations are standard for “next”: “14.2.15”, created using npx create-next-app@latest

Hi @rishabh-singh-codes! I don’t get that error with a fresh create-next-app project, but I believe your project has some additional customization added. If you can make the repo public or share a minimal reproducible example, then we can work together from the same code to debug this. :slightly_smiling_face:

Hey @amyegan, thanks for responding.

I too didn’t get any errors with fresh create-next-app project in my local. But I’m facing this issue after deploying it to vercel.

I’ve made the project public, you can have a look at it here: GitHub - Rishabh-Singh-Codes/caly: Schedule your calendar events

Specifically I’m using Object.groupBy function at two places:

  1. caly/src/lib/getValidTimesFromSchedule.ts at bf06d28db0d351361ba145d8fdcfd1e91d50b1a9 · Rishabh-Singh-Codes/caly · GitHub
  2. caly/src/components/forms/ScheduleForm.tsx at bf06d28db0d351361ba145d8fdcfd1e91d50b1a9 · Rishabh-Singh-Codes/caly · GitHub

You should be able to get this working with a polyfill. I built a minimal test app based on the repo you shared. That let me see the same error on both the deployed version and my local version (both using Node v20).

Here’s what I did to get it working:

  1. Run npm install core-js
  2. Add import "core-js/proposals/array-grouping-v2" to the files where Object.groupBy() is used
  3. Success! :tada:

In case you’re curious about why this is needed or how it works, I’m including some links to additional resources below. Please let me know if you continue to have trouble with it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.