Module not found when deploying in NextJs

2021-05-01T22:00:00Z

Hi everyone,

while trying to deploy my Next.js app in Netlify, I keep getting the following error:

ModuleNotFoundError: Module not found: Error: Can’t resolve ‘mongodb-client-encryption’ in ‘/opt/build/repo/node_modules/mongodb/lib’

Do you know how can I solve it?

Thank you for any help !

3:57:32 PM: info  - Creating an optimized production build...
3:57:50 PM: Failed to compile.
3:57:50 PM: 
3:57:50 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb-client-encryption' in '/opt/build/repo/node_modules/mongodb/lib'
3:57:50 PM: > Build error occurred
3:57:50 PM: Error: > Build failed because of webpack errors
3:57:50 PM:     at /opt/build/repo/node_modules/next/dist/build/index.js:17:924
3:57:50 PM:     at runMicrotasks (<anonymous>)
3:57:50 PM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
3:57:50 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:5:584)

This is how my package.json looks now:

{
  "name": "tangonext",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@auth0/nextjs-auth0": "^1.3.0",
    "@prisma/client": "^2.21.2",
    "mongodb": "^3.6.6",
    "next": "10.1.3",
    "next-auth": "^3.18.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "styled-components": "^5.2.3",
    "typeorm": "^0.2.32"
  },
  "devDependencies": {
    "netlify-plugin-cache-nextjs": "^1.6.1"
  }
}

I just tried as Build Commmand: CI=’ ’ npm run build - but it didn’t work

So, after digging around I found this page: https://www.mongodb.com/how-to/client-side-field-level-encryption-csfle-mongodb-node/

Which provides vast information regarding to cliente side encryption.
I installed the package that was missing, and got it to work.

I hope this fix will be durable :slightly_smiling_face:

have a good day!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.