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

使用i18next加载日语翻译文件时出现URL解析错误的问题求助

i18next加载日语翻译文件时出现URL解析错误的问题求助

我现在在用i18next做项目的国际化翻译,结果碰到了一个URL解析失败的错误,具体报错信息如下:

i18next::backendConnector: loading namespace translation for language ja failed TypeError: Failed to parse URL from /locales/ja/translation.json

at Object.fetch (node:internal/deps/undici/undici:11576:11) {

[cause]: TypeError [ERR_INVALID_URL]: Invalid URL

我已经把翻译文件放在了 /public/locales/ja/translation.json 路径下,而且JSON文件本身是有效的,浏览器的网络面板里也看不到失败的请求,所以我感觉大概率是配置哪里出问题了。

下面是我的i18n配置代码:

import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';

if (!i18n.isInitialized) {
  i18n
    .use(Backend)
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
      supportedLngs: ['en', 'ja'],
      fallbackLng: 'ja',
      debug: true,
    });
}

export default i18n;

有没有大佬能给点排查方向或者解决方案?非常感谢!

备注:内容来源于stack exchange,提问作者Andon Mitev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.20 13:08:17