Hi,
When I tried to build a project with
-
target: 'serverless'
withmongodb
package, I got this error:
ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb-client-encryption' in '/opt/build/repo/node_modules/mongodb/lib'
-
target: 'server'
, everything work fine but we landed onPage Not Found
- Why do we need to set
target: 'serverless'
? - How can we solve
ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb-client-encryption' in '/opt/build/repo/node_modules/mongodb/lib
when usingtarget: 'serverless'
? (I triedCI= npm run build
but still got the same error)
/my_folder
/pages
/api
test.js
index.js
next.config.js
package.json
// pages/api/test.js
import { MongoClient, ObjectID } from 'mongodb'
export default async function handler(req, res) {
res.send('ok')
}
// pages/index.js
export default function Home() {
return <h1>Hi</h1>
}
// next.config.js
const configs = {
target: 'serverless',
}
module.exports = configs
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"package": "next build && next export",
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"mongodb": "^3.6.8",
"next": "^10.2.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {},
"peerOptionalDependencies": {}
}
Thank you,