MongoDB saying Module not found: Can't resolve 'child_process'
Unanswered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Schneider’s Smooth-fronted CaimanOP
I have a fetch prefix function that gets prefixes from a db and its just saying that in console.
26 Replies
Schneider’s Smooth-fronted CaimanOP
src/utils/functions.ts
import { MongoClient, ServerApiVersion, Long } from 'mongodb';
export async function fetchPrefix(guildId: string) {
try {
client = await MongoClient.connect(process.env.MONGODB_URI, {
serverApi: {
version: '1'
}
});
console.log("Connected to MongoDB");
const astro = client.db("astro");
const prefixdb = astro.collection("prefixes");
const guildIdLong = Long.fromString(guildId);
const filter = { guild_id: guildIdLong };
const prefix = await prefixdb.findOne(filter);
return prefix;
} catch (err) {
console.error("Error connecting to MongoDB:", err);
throw err;
} finally {
if (client) {
await client.close();
}
}
}A reason for this error could be that the function is executed on the client, and since the client does not have access to packages/functions like 'child_process' it will cause an error.
A recommendation to fix this is to make it a server action. (In this case the only thing you would have to do is add "use server" in the top of your functions.ts file)
@Pearls A reason for this error could be that the function is executed on the client, and since the client does not have access to packages/functions like 'child_process' it will cause an error.
Schneider’s Smooth-fronted CaimanOP
./node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/client/components/react-dev-overlay/internal/helpers/use-websocket.js:68:5
Module not found: Can't resolve '@vercel/turbopack-ecmascript-runtime/dev/client/hmr-client.ts'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/client/components/react-dev-overlay/app/hot-reloader-client.js
./node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/client/components/app-router.js
./node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/client/app-call-server.js
./node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper.js
./src/utils/functions.ts
./src/pages/dashboard/[guildid].tsx now i get thisThats weird, could you restart your app and try again? If that still doesnt work maybe try it without using turbopack (remove the —turbo argument in the package.json -> "start": …)
@Pearls Thats weird, could you restart your app and try again? If that still doesnt work maybe try it without using turbopack (remove the —turbo argument in the package.json -> "start": …)
Schneider’s Smooth-fronted CaimanOP
i don't even have the turbo pack
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"child_process": false,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@clerk/nextjs": "^5.2.2",
"child_process": "^1.0.2",
"cookie": "^0.6.0",
"flowbite-react": "^0.10.1",
"mongodb": "^6.8.0",
"next": "^14.2.5",
"next-auth": "^4.24.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router": "^6.24.1",
"react-router-dom": "^6.24.1",
"tabler-icons-react": "^1.56.0",
"typeit-react": "^2.7.1"
},
"devDependencies": {
"@types/cookie": "^0.6.0",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"postcss": "^8.4.39",
"tailwindcss": "^3.4.4",
"typescript": "^5.5.3"
}
}Thats very confusing, just try restarting your app then ig. (Might be some caching issue, im not sure tho)
Schneider’s Smooth-fronted CaimanOP
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz_' -> 'C:\Users\harve\OneDrive\Documents\GitHub\Dashboard\.next\cache\webpack\client-development-fallback\1.pack.gz'@Pearls Thats very confusing, just try restarting your app then ig. (Might be some caching issue, im not sure tho)
Schneider’s Smooth-fronted CaimanOP
How do I clear my cache?
I didnt mean it like that, i meant like a runtime cache. Which is cleared when you restart the app
Schneider’s Smooth-fronted CaimanOP
well I've restarted it many times
Its still happening
Schneider’s Smooth-fronted CaimanOP
no idea how to fix this
hmm, can you share the full project? if yes then i could run it on my machine and try to fix it from there.
@Pearls hmm, can you share the full project? if yes then i could run it on my machine and try to fix it from there.
Schneider’s Smooth-fronted CaimanOP
https://github.com/Astro-Birb/Website/tree/main You might not get far as you need a lot of api keys
also some of the code ain't great
@Schneider’s Smooth-fronted Caiman also some of the code ain't great
Thats fine, all the code developers write will never be good enough, thats just how it is xD
Schneider’s Smooth-fronted CaimanOP

Yeah, theres too much missing keys for me to really find out how to fix it. But what i did notice is that fetchPrefix is never being called?
@Pearls Yeah, theres too much missing keys for me to really find out how to fix it. But what i did notice is that fetchPrefix is never being called?
Schneider’s Smooth-fronted CaimanOP
I kept the function I removed all the times I used it
My issue is that I wanted to use it as a function so didn't have to make an api request every time
I'm quite new to nextjs so everytime you go to a page it reloads the guild information
But it also does a discord api request when it loads the configuration info which means it keeps ratelimiting
I wanted to put it in a function to stop that from happening