When deploying my NextJS app, I am getting the following:
4:41:56 PM: info - Creating an optimized production build... 4:42:15 PM: Failed to compile. 4:42:15 PM: 4:42:15 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in '/opt/build/repo/node_modules/typeorm/platform' 4:42:15 PM: > Build error occurred 4:42:15 PM: Error: > Build failed because of webpack errors 4:42:15 PM: at /opt/build/repo/node_modules/next/dist/build/index.js:15:924 4:42:15 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584) 4:42:15 PM: npm ERR! code ELIFECYCLE 4:42:15 PM: npm ERR! errno 1 4:42:15 PM: npm ERR! firstname.lastname@example.org build: `next build` 4:42:15 PM: npm ERR! Exit status 1
I have seen this issue replicated with next JS before, see these issues:
It seems to be something to do with the fact that target: serverless is deprecated and also the fact that netlify cannot handle dynamic imports. See this issue:
Are there any workarounds? I am not familiar enough with the netlify system to know if there is a solution to this.