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

使用next-intl+NextJS14+TypeScript5遇TS2554错误求助

解决next-intl + NextJS 14 + TypeScript 5 中的TS2554错误

问题根源

你遇到的TS2554: Expected 0 arguments, but got 1错误,本质是next-intl版本与参考文档不匹配——当前安装的版本中createNavigation不需要接收参数,而你参考的文档对应了API有变更的版本(比如v4+)。

修复步骤

1. 适配next-intl v4+的API(推荐,适配NextJS14)

next-intl v4+重构了路由相关API,原createNavigation被createLocalizedPathnamesNavigation替代,需要传入routing参数。修改代码如下:

import { createLocalizedPathnamesNavigation } from "next-intl/navigation";
import { defineRouting } from "next-intl/routing";

export const routing = defineRouting({
  locales: ["en-US", "fr-CA", "nl-NL"],
  defaultLocale: "en-US",
});

export type Pathnames = keyof typeof routing.pathnames;
export type Locale = (typeof routing.locales)[number];

// 替换createNavigation为createLocalizedPathnamesNavigation
export const { Link, getPathname, redirect, usePathname, useRouter } =
  createLocalizedPathnamesNavigation(routing);

2. 锁定版本并同步文档

如果你不想升级API,可锁定next-intl到v3版本(对应你最初参考的文档):

npm install next-intl@3.x

之后确保代码完全遵循v3版本的官方文档示例。

3. 清除TypeScript缓存

执行以下命令清除TS缓存,避免旧错误残留:

rm -rf .next node_modules/.cache
npx tsc --noEmit

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 13:00:01