使用 clerk 中间件时,此 Edge Function 崩溃了

Ale*_*shi 5 typescript reactjs next.js vercel clerk

我尝试使用职员进行身​​份验证。在本地运行良好。但是,当我通过 vercel 在生产中部署时它不起作用。它表明This Edge Function has crashed.。我不知道这里发生了什么。有人有想法吗?我正在使用 nextjs 应用程序目录。

"react": "18.2.0",
"react-dom": "18.2.0",
"next": "13.4.12",
"next-intl": "^2.19.0",
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

中间件.ts

"react": "18.2.0",
"react-dom": "18.2.0",
"next": "13.4.12",
"next-intl": "^2.19.0",
Run Code Online (Sandbox Code Playgroud)

next.config.js

import { authMiddleware } from "@clerk/nextjs";
import createMiddleware from "next-intl/middleware";

const intlMiddleware = createMiddleware({
  locales: ["en", "zh"],
  defaultLocale: "en",
});

export default authMiddleware({
  beforeAuth: (req) => {
    return intlMiddleware(req);
  },

  publicRoutes: ["/"],
});

// export default authMiddleware();

export const config = {
  matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};

Run Code Online (Sandbox Code Playgroud)

Kar*_*ini 4

我也面临着同样的问题,但后来我意识到我忘记将环境变量添加到在 vercel 上部署的项目中,您可以通过访问 vercel 上项目的设置 -> 环境变量 -> 添加来添加环境变量环境变量。

确保添加 NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY 和 CLERK_SECRET_KEY 作为环境变量,您可以从职员仪表板获取这些变量。