After deploying nextjs app with nextAuth, I get 500 Server Internal Error

You can check the website here: https://test-prisma.netlify.app/

Jun 4, 02:14:23 AM: INIT_START Runtime Version: nodejs:18.v7	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:26e9402591d9c467cdcc7355f843d61968f36ecb6e9ef5ab253cc21163343275
Jun 4, 02:14:24 AM: 9c759b50 ERROR  Error: Cannot find module '/var/task/apps/nextjs/.next/server/pages/api/auth/[...nextauth].js'
Require stack:
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/apps/nextjs/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/_api_auth_nextauth-SPLAT-handler.js
- /var/task/_api_auth_nextauth-SPLAT-handler.js
- /var/runtime/index.mjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at /var/task/node_modules/next/dist/server/require-hook.js:180:36
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at NetlifyNextServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:653:34)
    at NetlifyNextServer.handleApiRequest (/var/task/node_modules/next/dist/server/next-server.js:1184:21)
    at Object.fn (/var/task/node_modules/next/dist/server/next-server.js:1127:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:315:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/apps/nextjs/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/_api_auth_nextauth-SPLAT-handler.js',
    '/var/task/_api_auth_nextauth-SPLAT-handler.js',
    '/var/runtime/index.mjs'
  ]
}
Jun 4, 02:14:24 AM: 9c759b50 INFO   [GET] /api/auth/session (API)
Jun 4, 02:14:24 AM: 9c759b50 Duration: 108.42 ms	Memory Usage: 96 MB	Init Duration: 477.40 ms
Jun 4, 02:14:24 AM: b7a4e271 ERROR  Error: Cannot find module '/var/task/apps/nextjs/.next/server/pages/api/auth/[...nextauth].js'
Require stack:
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/apps/nextjs/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/_api_auth_nextauth-SPLAT-handler.js
- /var/task/_api_auth_nextauth-SPLAT-handler.js
- /var/runtime/index.mjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at /var/task/node_modules/next/dist/server/require-hook.js:180:36
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at NetlifyNextServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:653:34)
    at NetlifyNextServer.handleApiRequest (/var/task/node_modules/next/dist/server/next-server.js:1184:21)
    at Object.fn (/var/task/node_modules/next/dist/server/next-server.js:1127:46)
    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:315:32)
    at async NetlifyNextServer.runImpl (/var/task/node_modules/next/dist/server/base-server.js:602:29) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/apps/nextjs/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/_api_auth_nextauth-SPLAT-handler.js',
    '/var/task/_api_auth_nextauth-SPLAT-handler.js',
    '/var/runtime/index.mjs'
  ]
}
Jun 4, 02:14:24 AM: b7a4e271 INFO   [POST] /api/auth/_log (API)
Jun 4, 02:14:24 AM: b7a4e271 Duration: 6.45 ms	Memory Usage: 97 MB

This kind of error happens to the trpc end point as well.

This is also the repo: GitHub - VibeFoundation/testing-drizzle: Checking if drizzle works well with netlify

2 Likes

Just commented this on another thread:

I’m also getting the 500 error with both my production and preview deploys when calling the next auth api to sign in. My production deploy was working well until a couple of hours ago, with no new commits since yesterday. No errors showing up in the logs. I believe the issue is likely with Netlify.

My app also uses NextAuth, NextJs and Prisma.

1 Like

Failed to mention that the site is working well locally.

Yeah, it works locally for me too

Same issue to me…

1 Like

I got the same issue as well.

Seems like it started yesterday, was working flawlessly before that. Also it works locally.

NextAuth, Next JS 13, TS

2 Likes

For all those affected, please share your site names.

@mast1999,

Could you try downgrading to Next.js Runtime v4.36.1: Release plugin-nextjs: v4.36.1 · netlify/next-runtime · GitHub

This is how you can specify the exact version to use: GitHub - netlify/next-runtime: The Next.js Runtime allows Next.js to run on Netlify with zero configuration

Others… we would need to see your sites to confirm what issue you’re having exactly. If the error is exactly the same, you can try downgrading as well. If you’re only seeing some 500 errors without that error message, it might be a different error.

3 Likes

@hrishikesh ,

thanks for the fix, downgrading the runtime seems to have fixed the issue for me.

This also worked for me. Thank you.

I am not using next.js runtime manually. I think, netlify sites (UI) automatically do this. I have the same error. Is there any way that I can solve this problem on Netlify UI
Web site: https://lunaportal.netlify.app

Hi there! This buggy behaviour is related to a bundling change i’m working on. For some context: Bundling the Netlify Functions currently takes a significant duration, for some sites more than 100secs. We found that this can be significantly reduced by using the .nft.json files that are documented by Next.js, to as low as a couple of seconds.

When I rolled this out (last friday), apparently there is some subtle bug that your sites were subjected to. I’ve reverted the rollout for now, and i’ll take a look at GitHub - VibeFoundation/testing-drizzle: Checking if drizzle works well with netlify to figure out what’s going on, if that’s okay with you @mast1999. I’ll post back here once I know more.

Thanks for bearing with me on this! Hopefully, your builds will be faster once i’m done :smiley:

1 Like

We’ve reverted the rollout. Your site should be working again, after you redeploy (see Manage deploys | Netlify Docs).

Hey

That’s totally fine with me. That’s a testing repo.

1 Like

My site is working well again. Thank you!

Thanks @skn0tt the site is not showing error any longer but now next-auth began not to work properly. When I try to login and fetching any url, I am having error. It was absolutely working in localhost two days before. Now I am having NEXTAUTH_URL client side fetching error for some reason. Session returns null and throw 401 error. I worked around server side rendering with MongoClient but I am not able to do client side fetching. Do you have any idea? I cleared also cookies. I am using next-auth 4.19.2 and next 13.1.6. In netlify, I used previous delpoy (about 7 days before) and everything works on production. For sure I cannot redeploy the site due to this reason.
Web site: www.lunazebrakatalog.com

are you still experiencing this?

Hi there! Thanks for bearing with me. I’ve identified a fix and released it as part of Release plugin-nextjs: v4.38.0 · netlify/next-runtime · GitHub. The rollout has just been restarted, and i’ll be closely monitoring any impact of this.

If you find your site to be behaving weirdly in any deployments made after 10:00 CET today, please let me know.

This didn’t fix it for me, and based off of all the threads with similar complaints I’m not the only one. Server.edge not defined Error on nextJS SSR functions cause site to return 500 Errors - #57 by Danimoz and Error 500 nextjs 13 dinamic routing - #11 by designtoy.
I tried the hacky prebuild script, I tried setting __NEXT_PRIVATE_PREBUNDLED_REACT as an env var, I tried downgrading the netlify/nextjs-plugin to both 4.36.1 and 4.37.4, none of it worked for simple server side function:

function ServerComponent({ serverData }: { serverData: string }) {
    console.log(serverData);

    return <div>Data: {serverData}</div>;
}

export async function getServerSideProps() {
    // Server-side code to fetch data
    const data = process.env.NEXTAUTH_URL;

    return {
        props: {
            serverData: JSON.stringify(data),
        },
    };
}

export default ServerComponent;

Deployed on Vercel and everything worked so will probably make the switch.

The devs are aware of the issue and working on it.