"top-level-await" error in Next.js 13 project #13419
-
I'm going crazy trying to figure this one out! All the courses and tutorials don't seem to show pulling in MongoDB data into a Next.js 13 project. I'm on Next.js 13.4 with Mongoose 7.1.1. I keep running into the following error:
The last line is merely my latest attempt at doing something with Mongoose, but I've tried connecting within a function inside a /app/ page and I've tried making a seemingly pointless internal API through the /api/route.ts method. But whenever I merely This is through running I saw this seemingly related suggestion to add Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Ah! Apparently, this is an incompatibility introduced with bson@5 in mongoose@7. When I downgraded to mongoose@6, everything worked as expected. |
Beta Was this translation helpful? Give feedback.
-
This worked for me, in your export const webpack = (config) => {
config.experiments = { ...config.experiments, topLevelAwait: true };
return config;
}; |
Beta Was this translation helpful? Give feedback.
This worked for me, in your
next.config.js
put the following