Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Error: Authentication crash when using PrismaAdapter (mongodb) - TypeError: Cannot read properties of undefined (reading 'exec') #12731

Open
th3f0r3ign3r opened this issue Mar 4, 2025 · 11 comments · May be fixed by #12755
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@th3f0r3ign3r
Copy link

Environment

System:
    OS: macOS 15.3.1
    CPU: (8) arm64 Apple M2
    Memory: 1.02 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    npm: 11.1.0 - ~/.nvm/versions/node/v22.14.0/bin/npm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 18.3
  npmPackages:
    @auth/prisma-adapter: ^2.8.0 => 2.8.0
    next: 15.2.0 => 15.2.0
    next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25
    react: ^19.0.0 => 19.0.0

Reproduction URL

https://github.com/th3f0r3ign3r/authjs-issue.git

Describe the issue

I have setting up Auth.js with Github Oauth and I decided to add PrismaAdapter with (mongodb) to save user account information. Without adding the adapter everything working great. But when I added the Adapter to @/auth it crash

Image

Image

CleanShot.2025-03-04.at.19.35.44.mp4

How to reproduce

  1. Clone the project
  2. Create a Github App (CLIENT_ID & CLIENT_SECRET)
  3. Create a MongoBD account and get a connection string
  4. Add them to the .env.local & run npx prisma generate
  5. Go to src/auth/index.tscomment the adapters line
  6. Launch the project clear && npm run dev don’t forget to run npm i
  7. Click on the Signin with GitHub
  8. After being logged signOut
  9. Uncomment the adapter line
  10. Refresh your browser

If you follow all these steps normally you will have the same error

Expected behavior

Normally they should not have any error. Instead I am doing something wrong but I follow the guide line per line. 😩😩😩

@th3f0r3ign3r th3f0r3ign3r added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Mar 4, 2025
@activemonkeys
Copy link

The @auth/prisma-adapter version ^2.8.0 is not compatible with next-auth version ^5.0.0-beta.25. To resolve this issue, revert to @auth/prisma-adapter version 2.7.2 and install it without the ^ symbol to prevent unintended updates.

@th3f0r3ign3r
Copy link
Author

The @auth/prisma-adapter version ^2.8.0 is not compatible with next-auth version ^5.0.0-beta.25. To resolve this issue, revert to @auth/prisma-adapter version 2.7.2 and install it without the ^ symbol to prevent unintended updates.

Thanks I will try it

@poksme
Copy link

poksme commented Mar 5, 2025

I am having the same error with a similar stack :

  npmPackages:
    @auth/prisma-adapter: ^2.8.0 => 2.8.0
    next: ^15.2.1 => 15.2.1
    next-auth: 5.0.0-beta.25 => 5.0.0-beta.25
    react: ^19.0.0 => 19.0.0

using PostgreSQL / Neon (I don't think the actual DB is related to this issue).

Thankfully, I got this error at build time, this was a bit more explicit than your logs :

> next build --experimental-build-mode compile
Failed to compile.

./src/lib/auth.ts
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

The error was caused by importing '@auth/prisma-adapter/index.js' in './src/lib/auth.ts'.

Import trace for requested module:
  ./src/lib/auth.ts
  ./src/middleware.ts

For reference, the source of the related files
lib/auth.ts

// Following this guide
// https://authjs.dev/getting-started/adapters/prisma
import { PrismaAdapter } from "@auth/prisma-adapter";
import type { PrismaNeon } from "@prisma/adapter-neon";
import type { PrismaClient } from "@prisma/client";
import type { NextAuthConfig } from "next-auth";
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";

import prisma from "@/lib/prisma";

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [GitHub],
  callbacks: {
    session({ session, user }) {
      // As seen on https://authjs.dev/guides/role-based-access-control
      if (user?.id) session.user.id = user.id;
      if (user?.role) session.user.role = user.role;
      return session;
    },
  },
  adapter: PrismaAdapter(
    prisma as PrismaClient<{ adapter: PrismaNeon }>,
  ) as NextAuthConfig["adapter"], // Need to type cast as we extend the payload of session
});

middleware.ts

// Only one middleware, used to refresh the token
export { auth as middleware } from "@/lib/auth";

@activemonkeys @th3f0r3ign3r not that it fixes the current problem, in my case I was able to lock version ~2.7.4 without issue.

@th3f0r3ign3r
Copy link
Author

The @auth/prisma-adapter version ^2.8.0 is not compatible with next-auth version ^5.0.0-beta.25. To resolve this issue, revert to @auth/prisma-adapter version 2.7.2 and install it without the ^ symbol to prevent unintended updates.

I almost forgot my problem is solved
Thanks @activemonkeys

@th3f0r3ign3r
Copy link
Author

I am having the same error with a similar stack :

  npmPackages:
    @auth/prisma-adapter: ^2.8.0 => 2.8.0
    next: ^15.2.1 => 15.2.1
    next-auth: 5.0.0-beta.25 => 5.0.0-beta.25
    react: ^19.0.0 => 19.0.0

using PostgreSQL / Neon (I don't think the actual DB is related to this issue).

Thankfully, I got this error at build time, this was a bit more explicit than your logs :

> next build --experimental-build-mode compile
Failed to compile.

./src/lib/auth.ts
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

The error was caused by importing '@auth/prisma-adapter/index.js' in './src/lib/auth.ts'.

Import trace for requested module:
  ./src/lib/auth.ts
  ./src/middleware.ts

For reference, the source of the related files
lib/auth.ts

// Following this guide
// https://authjs.dev/getting-started/adapters/prisma
import { PrismaAdapter } from "@auth/prisma-adapter";
import type { PrismaNeon } from "@prisma/adapter-neon";
import type { PrismaClient } from "@prisma/client";
import type { NextAuthConfig } from "next-auth";
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";

import prisma from "@/lib/prisma";

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [GitHub],
  callbacks: {
    session({ session, user }) {
      // As seen on https://authjs.dev/guides/role-based-access-control
      if (user?.id) session.user.id = user.id;
      if (user?.role) session.user.role = user.role;
      return session;
    },
  },
  adapter: PrismaAdapter(
    prisma as PrismaClient<{ adapter: PrismaNeon }>,
  ) as NextAuthConfig["adapter"], // Need to type cast as we extend the payload of session
});

middleware.ts

// Only one middleware, used to refresh the token
export { auth as middleware } from "@/lib/auth";

@activemonkeys @th3f0r3ign3r not that it fixes the current problem, in my case I was able to lock version ~2.7.4 without issue.

Great 👍 I will try 2.7.4 to see if it will still work.

@abrunner94
Copy link

Shit like this is exactly why I hate but also love NextAuth, Auth.js, whatever we call it today.

@poksme
Copy link

poksme commented Mar 6, 2025

@th3f0r3ign3r I am not sure why you consider this issue solved, I think prisma-adapter ^2.8.0 is supposed to work with ^5.0.0-beta.25. @activemonkeys and I were just providing a stopgap solution until the issue is fixed.

@th3f0r3ign3r th3f0r3ign3r reopened this Mar 6, 2025
@th3f0r3ign3r
Copy link
Author

@th3f0r3ign3r I am not sure why you consider this issue solved, I think prisma-adapter ^2.8.0 is supposed to work with ^5.0.0-beta.25. @activemonkeys and I were just providing a stopgap solution until the issue is fixed.

my bad though

@bunnyxt
Copy link

bunnyxt commented Mar 8, 2025

Same here, for PrismaAdapter with Postgres

@QC2168

This comment has been minimized.

@i-naeem
Copy link

i-naeem commented Mar 12, 2025

The @auth/prisma-adapter version ^2.8.0 is not compatible with next-auth version ^5.0.0-beta.25. To resolve this issue, revert to @auth/prisma-adapter version 2.7.2 and install it without the ^ symbol to prevent unintended updates.

I almost forgot my problem is solved Thanks @activemonkeys

Thanks for pointing this out! I was facing the same issue, and downgrading @auth/prisma-adapter to 2.7.2 worked for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants