Home
Support Forums

Next Auth Deploy Issues with Netlify and NextJS

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! bedrock-sms@0.1.0 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.

Hi there, @pcbowers

Thanks for reaching out, and welcome to the Netlify Forums :netliconfetti:

It looks like this thread has been quiet for the past week. Are you still searching for a workaround? If so, let me know and I will loop in our nextjs folks. If not, please feel free to share any changes you made or steps you have taken in the interim :slight_smile:

Hi @hillary

I’m getting a similar issue to the above. I’m not using mongodb but when building the site I get the module not found issue.

I think it may be the way the /opt/build/repo/node_modules/typeorm/platform is being dealt with in the build process. If I explicitly add mongodb as a dependency then the build fails on the next database package (e.g. msql, mysql2, oracledb etc.) in a similar way to this post

Most recent failed build:

I found this issue on the next-auth repo. I’m also not sure if this is an issue with the change to webpack 5 as I was getting successful builds with webpack 4 and haven’t changed anything recently.

Let me know if you need anything else

Thanks

Hey there, @Tim_Booth :wave:

Can you please share your site as well as your public repo with us? That would help us look into this further. Thanks!

Hi @hillary

No Problem, I’ve created a public repo with my code and linked it to a new netlify site that I can share. This is having the same issue on build.

Removed Public Repo and site after issue fixed

Hey @Tim_Booth,

I think you’ll be interested in following along with this issue in our Next.js plugin repo!

1 Like

Thanks that looks to be exactly the issue I am getting. I will have a go a deploying with e-s-t as suggested in the above.

Hi @Scott, just wanted to confirm that setting the target to experimental-serverless-trace in next.config.js did the trick. I have a successful build. Thanks for the help

1 Like

Hey there, @Tim_Booth

Thanks so much for circling back and letting us know! Glad you have a successful build now :netliconfetti:

1 Like