gpt4 book ai didi

gatsby - i18n 错误(错误 : You are passing an undefined module! 请检查您传递给 i18next.use() 的对象)

转载 作者:行者123 更新时间:2023-12-04 12:37:37 24 4
gpt4 key购买 nike

我正在尝试在我的 Gatsby 项目中设置 i18n。
我一直在一步一步地学习本教程:
https://www.gatsbyjs.org/blog/2017-10-17-building-i18n-with-gatsby/
首先我下载所需的包:

npm i -S i18next i18next-xhr-backend i18next-browser-languagedetector react-i18next
然后我设置了 i18n 组件
import i18n from "i18next"
import Backend from "i18next-xhr-backend"
import LanguageDetector from "i18next-browser-languagedetector"
import { reactI18nextModule } from "react-i18next"

i18n
.use(Backend)
.use(LanguageDetector)
.use(reactI18nextModule)
.init({
fallbackLng: "en",

// have a common namespace used around the full app
ns: ["translations"],
defaultNS: "translations",

debug: true,

interpolation: {
escapeValue: false, // not needed for react!!
},

react: {
wait: true,
},
})

export default i18n
在我的布局组件中导入它:
import React from "react"
import "./layout.scss"
import NavMenu from "./NavMenu/navMenu"
import i18n from './i18n/i18n'

export default function Layout({ children }) {
return (
<div className="container">
<NavMenu />
{children}
</div>
)
}
但是,当我运行我的应用程序时,出现以下错误:
enter image description here
有谁知道问题可能是什么?

最佳答案

进口自 react-i18next是错的。它应该是import { initReactI18next } from "react-i18next".use(initReactI18next)如果您尝试导入未导出的内容,则该值未定义,然后 use给你你看到的消息。
好像叫reactI18nextModulereact-i18next 的早期版本中这就是为什么你可以找到使用它的教程。
我做了一个 demonstration of the exports in RunKit

关于gatsby - i18n 错误(错误 : You are passing an undefined module! 请检查您传递给 i18next.use() 的对象),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62849265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com