mongodb + nextjs
Answered
Shawty posted this in #help-forum
ShawtyOP
i am currently getting a error with mongodb when using nextjs although all my mongodb code is server side.
error:
the file
has nothing even related to mongodb. it doesnt use it at all.
index.tsx
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,
},
};
}
8 Replies
ShawtyOP
i also cant tell if the error it referring to
src/pages/dashboard/index.tsx
or src/pages/dashboard/[id]/index.tsx
I finally found someone with my exact issue
@Shawty are you fetching mongodb data in api routes? i think that was my issue
(that i wasn’t)
@clarity <@435258578128076801> are you fetching mongodb data in api routes? i think that was my issue
ShawtyOP
i was trying to fetch it client side haha
ShawtyOP
i fixed it by moving all the code into server side
Answer
same