Next.js Discord

Discord Forum

mongodb + nextjs

Answered
Shawty posted this in #help-forum
Open in Discord
Avatar
ShawtyOP
i am currently getting a error with mongodb when using nextjs although all my mongodb code is server side.

error:
./node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js:34:24
Module not found: Can't resolve 'child_process'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js
./node_modules/mongodb/lib/index.js
./src/database/mongo.ts
./src/utils/check.js
./src/pages/dashboard/index.tsx




the file dashboard/index.tsx
has nothing even related to mongodb. it doesnt use it at all.

index.tsx
export default function Index({data: botGuilds}: { data: PartialGuild[] }) {
    const {data: session, status} = useSession();
    if (status == "loading") return <LoadingPage/>
    if (!session) return <AccessDenied/>;
    const {user} = session;
    // @ts-ignore
    const {guilds} = user as { guilds: PartialGuild[] };

    return (
//html
)
}

export async function getServerSideProps() {

    const res = await getBotGuilds();
    const data = await res.json();

    // Pass the fetched data as props to the page component
    return {
        props: {
            data,
        },
    };
}
Answered by Shawty
i fixed it by moving all the code into server side
View full answer

8 Replies

Avatar
ShawtyOP
i also cant tell if the error it referring to src/pages/dashboard/index.tsx or src/pages/dashboard/[id]/index.tsx
Avatar
clarity
I finally found someone with my exact issue :plusone:
Avatar
clarity
@Shawty are you fetching mongodb data in api routes? i think that was my issue
(that i wasn’t)
Avatar
ShawtyOP
i was trying to fetch it client side haha
Avatar
ShawtyOP
i fixed it by moving all the code into server side
Answer
Avatar
clarity
same
:high_five: