You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js构建错误:_buildManifest.js类型不兼容问题求助

Next.js构建时_buildManifest.js类型错误修复方案

问题描述

构建Next.js项目时触发_buildManifest.js文件类型错误,该文件预期符合Record<string, string[]>类型,但当前文件包含__rewrites对象,与索引签名不兼容。具体错误信息如下:

./out/_next/static/-odsiyNLTJ-AH9P5Rvh0d/_buildManifest.js:1:1
@ziffichess/web-client:build: Type error: Type '{ __rewrites: { afterFiles: never[]; beforeFiles: never[]; fallback: never[]; }; "/": string[]; "/404": string[]; "/_error": string[]; "/about-us": string[]; "/account-suspended": string[]; "/activate-battle-mode-v2": string[]; "/auth/login": string[]; "/auth/verify-otp": string[]; "/auth/[[...path]]": string[]; "/battle-mode": string[]; "/daily-league": string[]; "/delete-account": string[]; "/fair-play-policy": string[]; "/invite-and-earn": string[]; "/invite-and-earn/my-invites": string[]; "/invite-and-earn/terms-and-conditions": string[]; "/onboarding": string[]; "/privacy-policy": string[]; "/room/[roomID]": string[]; "/rules": string[]; "/terms-and-conditions": string[]; "/test-sentry": string[]; "/tournament": string[]; "/tournament/[tournamentID]": string[]; "/tournament/[tournamentID]/leaderboard": string[]; "/tournament/[tournamentID]/progress": string[]; "/transaction-history": string[]; "/transaction-history/transaction-details": string[]; "/transaction-history/transaction-details/[walletTransactionId]": string[]; "/waiting-room/[roomID]": string[]; "/wallet": string[]; "/wallet/kyc": string[]; "/wallet/recharge": string[]; "/withdraw": string[]; sortedPages: string[]; }' is not assignable to type 'Record<string, string[]>'.
@ziffichess/web-client:build:   Property '__rewrites' is incompatible with index signature.
@ziffichess/web-client:build:     Type '{ afterFiles: never[]; beforeFiles: never[]; fallback: never[]; }' is missing the following properties from type 'string[]': length, pop, push, concat, and 29 more.

修复步骤

1. 对齐Next.js与类型定义版本

该问题常因Next.js版本和@types/next版本不匹配导致:

  • 确保next和@types/next版本严格对应,比如Next.js 13.x配套@types/next@13.x
  • 执行命令更新到最新稳定版:npm install next@latest @types/next@latest,或回退至之前可正常构建的版本

2. 自定义类型覆盖(临时方案)

若暂时无法调整版本,可通过自定义类型声明修正类型冲突:

  • 在项目根目录创建types/next.d.ts文件
  • 添加以下内容:
declare module 'next/dist/build/output/public/_buildManifest' {
  interface BuildManifest {
    __rewrites?: {
      afterFiles: never[];
      beforeFiles: never[];
      fallback: never[];
    };
    sortedPages?: string[];
    [key: string]: string[] | undefined;
  }

  const buildManifest: BuildManifest;
  export default buildManifest;
}
  • 确保tsconfig.json的include数组包含该类型文件路径,比如"types/**/*.d.ts"

3. 排查路由配置异常

自定义路由规则可能导致__rewrites生成格式错误:

  • 检查next.config.js中的rewrites、redirects等配置,确认无语法或返回格式问题
  • 尝试注释自定义路由配置后重新构建,逐步定位异常配置项

4. 清理构建缓存

缓存文件可能残留旧类型信息:

  • 删除.next和out目录:Linux/macOS执行rm -rf .next out,Windows执行rmdir /s .next out
  • 重新执行npm run build构建项目

内容的提问来源于stack exchange,提问作者neha gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 13:12:24