Next.js 中 useSession() 返回 null
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子...
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子...
Vercel 构建时 TypeScript 检查失败,可以在 next.config.ts 中设置 typescript.ignoreBuildErrors = true 临时跳过,但不推荐。正确做法:本地运行 npm run typecheck 修复所有类型错误后再部署。 Prisma 事务中...
Prisma $queryRaw 中 camelCase 列名必须加双引号:SELECT "newUserQuota" FROM users。不加双引号 PostgreSQL 会当作不区分大小写的标识符,找不到 camelCase 列。TS 类型声明也要与 SQL 别名一致。 Auth.js JW...
Next.js middleware 中 pathname 精确匹配失效,因为 intl 中间件处理后 pathname 含 locale 前缀(如 /zh/dashboard)。用 pathname.includes() 或 getLocaleFromPathname() 而非 pathname...
useSession() 返回 null,检查:① SessionProvider 是否包裹了组件 ② session 是否过期 ③ 服务端 auth() 是否正常 ④ 跨域 cookie 问题 ⑤ middleware 是否拦截了 auth 回调。 Server Action 提交后不跳转,可能...
next/image 图片模糊或变形,检查:① 是否设置了 width/height 或 fill ② fill 模式需要父容器 position: relative ③ priority 只给 LCP 图片 ④ sizes 属性帮助浏览器选择正确尺寸 ⑤ 避免在 Server Component...
next-intl t() 模板字符串拼接报错,因为动态拼接翻译键不被支持。用显式 Record 映射替代 t(`${type}Opt`),改为 const labels: Record<string, string> = { ... } 然后 labels[type]。 generateStat...
router.push 不更新 URL,Next.js 15 + next-intl 在 useSession 触发 re-render 时可能取消 router.push 的 startTransition。解决:用 window.location.href 硬导航(认证流程的例外允许裸路径)。...
Next.js 动态 import 水合报错,可能是动态组件的 SSR 输出与客户端不一致。加 ssr: false 避免服务端渲染,或确保组件在 SSR 和 CSR 中输出一致。 router.push 不更新 URL,Next.js 15 + next-intl 在 useSession 触发...
revalidateTag vs revalidatePath:revalidateTag 清除特定 tag 的缓存(fetch 时用 next.tags 标记),revalidatePath 清除特定路径的缓存。数据变更后 revalidatePath 更直接,精细控制用 revalidateTa...
Next.js middleware 中 pathname 精确匹配失效,因为 intl 中间件处理后 pathname 含 locale 前缀(如 /zh/dashboard)。用 pathname.includes() 或 getLocaleFromPathname() 而非 pathname...
Prisma 多对多关系创建,用 connect 或 create 连接:prisma.user.create({ data: { roles: { connect: [{ id: roleId }] } } })。隐式多对多表 Prisma 自动管理,显式多对多需要自己管理中间表。 Next.j...
Prisma enum 在 TypeScript 中报错,确保:① 运行了 prisma generate ② import { Prisma } from '@prisma/client' 取枚举值 ③ 不要用字符串字面量而用 Prisma.EnumType 枚举 ④ schema 中 enum...
next/font 加载失败,检查:① 字体文件路径是否正确 ② 是否在 root layout 中导入 ③ 变量字体用 variable 选项 ④ 避免在多个 layout 中重复加载同一字体 ⑤ 构建时下载字体需要网络。 Next.js 动态 import 水合报错,可能是动态组件的 SSR...
Prisma 连接池超时一般是 connection_limit 设置不当。Serverless 环境(Vercel)建议 connection_limit=1,因为每个函数实例独立连接。如果用 PgBouncer 或 Supabase connection pooler,URL 加 ?pgboun...
Prisma 连接池超时一般是 connection_limit 设置不当。Serverless 环境(Vercel)建议 connection_limit=1,因为每个函数实例独立连接。如果用 PgBouncer 或 Supabase connection pooler,URL 加 ?pgboun...
Vercel 构建时 TypeScript 检查失败,可以在 next.config.ts 中设置 typescript.ignoreBuildErrors = true 临时跳过,但不推荐。正确做法:本地运行 npm run typecheck 修复所有类型错误后再部署。 Prisma migr...
Vercel Edge Runtime 不支持 Prisma,因为 Prisma 依赖 Node.js 原生模块。Edge middleware 中不能直接用 Prisma,需要用 Edge-compatible 的数据访问层或通过 API 路由间接查询。 router.push 不更新 URL,...
next-intl t() 模板字符串拼接报错,因为动态拼接翻译键不被支持。用显式 Record 映射替代 t(`${type}Opt`),改为 const labels: Record<string, string> = { ... } 然后 labels[type]。 Auth.js cred...
next-intl 配置后 404,一般是 middleware 匹配规则不对。检查 middleware.ts 中 matcher 配置,确保排除了 /api、/_next、/admin 等非国际化路径。另外检查 defaultLocale 和 locales 配置是否正确。 React Ser...