Ever since today, I've been encountering an issue when trying to establish a connection to MongoDB using Mongoose within my Next.js application. The error message I'm getting is as follows. Can anyone provide some guidance on how to resolve this?
Uncaught (in promise) TypeError: mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).connect is not a function at mongoDBConnection
app/new/FileUpload.tsx:
import mongoDBConnection from "../lib/mongoDb";
useEffect(()=> mongoDBConnection()),[]}
app/lib/mongoDB.ts:
import mongoose from "mongoose";
const mongoDBConnection = async () =>
await mongoose.connect(process.env.MONGO_URL as string);
export default mongoDBConnection;
next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.experiments = { ...config.experiments, topLevelAwait: true };
return config;
},
reactStrictMode: true,
experimental: {
serverActions: true,
appDir: true,
serverComponentsExternalPackages: ["mongoose"],
},
images: {
domains: ["fakestoreapi.com", "firebasestorage.googleapis.com"],
},
};
module.exports = nextConfig;