Recommand · November 24, 2021 0

nextjs getting mongodb dns error on page load

Currently creating a nextjs app with mongodb and I’m currently getting the following error and it’s driving me nuts trying to solve it

Failed to compile
./node_modules/mongodb/lib/cmap/auth/gssapi.js:8:0
Module not found: Can't resolve 'dns'

Import trace for requested module:
./node_modules/mongodb/lib/cmap/auth/defaultAuthProviders.js
./node_modules/mongodb/lib/index.js
./lib/mongodb.js
./pages/dashboard/index.js

https://nextjs.org/docs/messages/module-not-found

any help would be great to avoid issues like this in future.

EDIT

I’ve tried yarn add dns

but that wouldn’t install