Is next-auth compatible with NextJS Edge Runtime ? #5855
-
Build is failing with the following error $ pnpm run build
> my-app@ build /mnt/data/projects/my-app
> next build
info - Loaded env from /mnt/data/projects/my-app/.env
warn - You have enabled experimental feature (runtime) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Linting and checking validity of types
warn - You are using the experimental Edge Runtime with `experimental.runtime`.
info - Creating an optimized production build
Failed to compile.
./node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/regenerator/index.js
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
Import trace for requested module:
./node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/regenerator/index.js
./node_modules/.pnpm/[email protected]_dcors23iqtgxrhrwosgnnc4xji/node_modules/next-auth/core/errors.js
./node_modules/.pnpm/[email protected]_dcors23iqtgxrhrwosgnnc4xji/node_modules/next-auth/utils/logger.js
./node_modules/.pnpm/[email protected]_dcors23iqtgxrhrwosgnnc4xji/node_modules/next-auth/core/index.js
./node_modules/.pnpm/[email protected]_dcors23iqtgxrhrwosgnnc4xji/node_modules/next-auth/next/index.js
./node_modules/.pnpm/[email protected]_dcors23iqtgxrhrwosgnnc4xji/node_modules/next-auth/index.js
> Build failed because of webpack errors
ELIFECYCLE Command failed with exit code 1.
/**
* @type {import('next').NextConfig}
*/
module.exports = {
reactStrictMode: true,
swcMinify: true,
experimental:{
runtime:"experimental-edge"
},
};
import NextAuth, { NextAuthOptions } from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'
export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
],
theme: {
colorScheme: 'light',
},
}
export default NextAuth(authOptions) Is this a known limitation or am I doing something wrong ? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 21 replies
-
Commenting to follow along, was hoping to implement as a solution to the (sometimes long) delay between Signup() and actually redirecting user to the /login page. Vercel's Edge documentation points out, however, that "you cannot use Node.js APIs in Edge Functions. See the Limitations section for more information." May be a potential issue. |
Beta Was this translation helpful? Give feedback.
-
Hi, NextAuth.js ( PR here: #7443 |
Beta Was this translation helpful? Give feedback.
-
I solved the issue using the experimental version as @balazsorban44 suggested. I used [email protected] and [email protected]. What I did:
const authOptions: NextAuthConfig = {
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}) as Provider,
],
secret: process.env.GOOGLE_CLIENT_SECRET,
pages: {
signIn: "/signin",
},
};
const handler = NextAuth(authOptions);
export const GET = handler.handlers.GET;
export const POST = handler.handlers.POST;
export const runtime = "edge";
|
Beta Was this translation helpful? Give feedback.
-
Any updates for version 5 @balazsorban44 ?
|
Beta Was this translation helpful? Give feedback.
-
is my error
same as this thread's ? |
Beta Was this translation helpful? Give feedback.
-
I came to this issue from google search, and after more research I found the new auth.js support edge runtime. https://authjs.dev/guides/edge-compatibility , migrating to auth.js is working for me. |
Beta Was this translation helpful? Give feedback.
Hi, NextAuth.js (
next-auth
) is not runtime agnostic, but the next generation@auth/nextjs
will be, which is based on the new@auth/core
, announced here: https://twitter.com/balazsorban44/status/1603082914362986496PR here: #7443