There are a lot of errors in my application console.
How to fix it?
Next js 13.2 / app directory
Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/CognitoIdentityClient.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/index.js
./node_modules/@aws-sdk/credential-providers/dist-cjs/fromCognitoIdentity.js
./node_modules/@aws-sdk/credential-providers/dist-cjs/index.js
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js
./node_modules/mongoose/node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in 'C:Users79833WebstormProjectspartAppnode_modulesmongoosenode_modulesmongodblib'
Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/bson.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in 'C:Users79833WebstormProjectspartAppnode_modulesmongoosenode_modulesmongodblib'
Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@mongodb-js/zstd' in 'C:Users79833WebstormProjectspartAppnode_modulesmongoosenode_modulesmongodblib'
Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js
I have tried updating and reinstalling packages. The error does not go away.
These are not all errors. There are many others. They also look
2
Answers
In nextjs you have to export the schema like this this will fix your issue
These are the things i’ve learned by spending time using mongoose 7 with latest nextjs version:
Make sure that mongoose is not imported inside client components ! (Which were creating Can’t resolve errors that you are facing)
And if you are using mongoose 7, I have to put serverComponentsExternalPackages option in next.config.js (even with the fix given here https://github.com/vercel/next.js/issues/42277)
I would also change your export by
my project https://github.com/mathieuguyot/adventures have mongoose 7 integrated with next 13.2.4, maybe it can help you in any way 🙂