我正在尝试在我的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>
)
}然而,当我运行我的应用程序时,我得到了以下错误:

有谁知道问题出在哪里吗?
发布于 2020-07-12 21:09:04
从react-i18next导入错误。它应该是
import { initReactI18next } from "react-i18next"
和
.use(initReactI18next)
如果您尝试导入未导出的内容,则该值未定义,然后use会给出您所看到的消息。
它似乎在react-i18next的早期版本中被称为reactI18nextModule,这就是为什么你可以找到使用它的教程。
https://stackoverflow.com/questions/62849265
复制相似问题