Mongodb regex works on localhost but not on Vercel

59 Views Asked by At

I have the following code:

import { User } from "@/mongo";
import { SearchBar, UserRating } from "./components";

type searchParams = {
    email?: string;
  };
export default async function Search({ searchParams }: { searchParams:  searchParams}) {

    const isCustomer = true;
    
    const users = await User.find({email: {$regex: searchParams.email ?  searchParams.email : ""}})

    return (
        <>
            <SearchBar />
            <section className="reviews">
                {users.map((user, i) => (
                    <UserRating stars={user.customerRating} isCustomer={isCustomer} author={user._id} key={i}/>
                ))}
            </section>
        </>
    );
}

This is a Next.js 14 page with Mongoose. It is checking if an email query param exists and if so it will add email to the query. This works fine on localhost and even a production build on my local machine but not Vercel.

Other MongoDB calls work just not this one.

Here is the error I'm getting on the Vercel build logs:


RangeError: Maximum call stack size exceeded
    at RegExp.exec (<anonymous>)
    at create (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:18889)
    at create (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:18918)
    at create (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:18918)
    at parse.fastpaths (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:18997)
    at picomatch.makeRe (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:21635)
    at picomatch (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19637)
    at /vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19294
    at Array.map (<anonymous>)
    at picomatch (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19286)
Error: Command "npm run build" exited with 1

This is the only place I'm using the MongoDB regex operator.

What is wrong? I have the proper Vercel env.

I'm using MongoDB 6.3.0 and Mongoose 8.

1

There are 1 best solutions below

0
Kinppo On

I had the same error log, It was caused by bcryptjs, I fixed it by replacing it with bcrypt.