Getting Module not found when deploying a next.js with mongodb in it

Hi everyone,
I’m still getting this error when deploying my application ( https://tangolibre-nextjs.netlify.app )

Any help will be appreciated!

12:09:20 PM: info - Checking validity of types…
12:09:20 PM: info - Creating an optimized production build…
12:09:39 PM: Failed to compile.
12:09:39 PM:
12:09:39 PM: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘mongodb-client-encryption’ in ‘/opt/build/repo/node_modules/mongodb/lib’
12:09:39 PM: > Build error occurred
12:09:39 PM: Error: > Build failed because of webpack errors
12:09:39 PM: at /opt/build/repo/node_modules/next/dist/build/index.js:17:924
12:09:39 PM: at runMicrotasks ()
12:09:39 PM: at processTicksAndRejections (internal/process/task_queues.js:97:5)
12:09:39 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:5:584)
12:09:39 PM: npm ERR! code ELIFECYCLE
12:09:39 PM: npm ERR! errno 1
12:09:39 PM: npm ERR! tangonext@0.1.0 build: next build
12:09:39 PM: npm ERR! Exit status 1
12:09:39 PM: npm ERR!
12:09:39 PM: npm ERR! Failed at the tangonext@0.1.0 build script.
12:09:39 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:09:39 PM: npm ERR! A complete log of this run can be found in:
12:09:39 PM: npm ERR! /opt/buildhome/.npm/_logs/2021-05-03T10_09_39_971Z-debug.log
12:09:40 PM: ​
12:09:40 PM: ────────────────────────────────────────────────────────────────
12:09:40 PM: “build.command” failed
12:09:40 PM: ────────────────────────────────────────────────────────────────
12:09:40 PM: ​
12:09:40 PM: Error message
12:09:40 PM: Command failed with exit code 1: npm run build
12:09:40 PM: ​
12:09:40 PM: Error location
12:09:40 PM: In Build command from Netlify app:
12:09:40 PM: npm run build
12:09:40 PM: ​

@matiasfacio Welcome to the Netlify community.

I’m no expert on this topic, but are you trying to use MongoDB in the cloud or are you trying to spin up your own MongoDB? I ask because I’m guessing that Netlify does not allow you to spin up a database.

Hi Greg, thank you for your attention. And no, I’m not trying to spin up a database in Netlify, the database is hosted somewhere else, in Mongo Atlas I believe it is called.

So, I found an article regarding to client side encrypting for MongoDB. It is quite informative.
The only thing I did which solved my problem was to install that missing package. If this is a long term solution, I really don’t know.
I did follow the tutorial for how to begin using MongoDB on a next js app. It didn’t mention anything regarding to this special package and the need to install it for deploying at least as it worked locally. I don’t know the reason it is not mention there, but may be I missed something.
So, that’s it!
Thank you

1 Like

Hey there, @matiasfacio :wave:

Thanks so much for coming back and sharing your solution! This will definitely be helpful to future Forums members, and is part of what makes this space great :netlisparkles: