最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nextjs 15 - Build fails for Next.js Failed to collect page data for apiauth[...nextauth] - Stack Overflow

programmeradmin0浏览0评论

In my local and development environment everything works fine. But when npm run build, the following error shows up.

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import axios from "axios";

const authOptions = {
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        phone: { label: "Phone", type: "text" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        try {
          // Call your external login endpoint
          const response = await axios.post(
            process.env.NEXT_PUBLIC_API_BASE_URL + "/login",
            {
              payload: {
                username: credentials.phone,
                password: credentials.password,
              },
            }
          );
          // If login is successful, return the user object
          if (response.data) {
            return response.data;
          }
          return null;
        } catch (error) {
          console.error(
            "Error during login:",
            error.response?.data || error.message
          );
          return null;
        }
      },
    }),
  ],
  session: {
    strategy: "jwt",
  },
  callbacks: {
    async jwt({ token, user }) {
      // Merge user data into token on initial sign in
      if (user) token = { ...token, ...user };
      return token;
    },
    async session({ session, token }) {
      // Make token (user data) available in session
      session.user = token;
      return session;
    },
  },
  pages: {
    signIn: "/auth/login", // Custom sign-in page route if desired
    signOut: "/",
  },
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

This is package.json script

 "scripts": {
    "dev": "next dev --turbopack -p 3500",
    "build": "next build --debug",
    "start": "next start",
    "lint": "next lint"
  },

The error in console:

Collecting page data ..TypeError: f is not a function at 17950 (C:\Users\Acer\Desktop....next\server\app\api\auth[...nextauth]\route.js:11:26405) at t (C:\Users\Acer\Desktop....next\server\webpack-runtime.js:1:128) at r (C:\Users\Acer\Desktop....next\server\app\api\auth[...nextauth]\route.js:36:219820)

I tried removing blocks of the [...nextauth]/route.js but it is not working

发布评论

评论列表(0)

  1. 暂无评论