【问题标题】:react-i18next getting error Attempted import errorreact-i18next 出现错误尝试导入错误
【发布时间】:2020-10-07 07:55:36
【问题描述】:

我尝试使用https://react.i18next.com/ 对于本地化,我收到错误:尝试导入错误:“initReactI18next”未从“react-i18next”导出。

这是我的 i18n.js 文件:

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
// not like to use this?
// have a look at the Quick start guide 
// for passing in lng and translations on init

i18n
  // load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
  // learn more: https://github.com/i18next/i18next-http-backend
  .use(Backend)
  // detect user language
  // learn more: https://github.com/i18next/i18next-browser-languageDetector
  .use(LanguageDetector)
  // pass the i18n instance to react-i18next.
  .use(initReactI18next)
  // init i18next
  // for all options read: https://www.i18next.com/overview/configuration-options
  .init({
    fallbackLng: 'en',
    debug: true,

    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    }
  });


export default i18n;

我的 package.json

{ "name": "heatmann", "version": "0.1.0", "private": true,
“依赖”:{ "axios": "^0.19.0", "i18next": "^19.4.5", "i18next-browser-languagedetector": "^4.3.0", "i18next-http-backend": "^1.0.15", "i18next-xhr-backend": "^3.2.2", “道具类型”:“^15.7.2”, "proptypes": "^1.1.0", “反应”:“^16.12.0”, “反应爱丽丝轮播”:“^1.17.2”, “反应域”:“^16.12.0”, "react-i18next": "^9.0.10", "react-loader-spinner": "^3.1.5", "react-native-gesture-handler": "^1.5.2", “反应导航”:“^4.0.10”, “反应导航堆栈”:“^1.10.3”, "react-router-dom": "^5.1.2", “反应脚本”:“^3.3.0”},“脚本”:{ “开始”:“反应脚本开始”, "build": "react-scripts build", "test": "react-scripts 测试", “弹出”:“反应脚本弹出”},“eslintConfig”:{ “扩展”:“反应应用程序”},“浏览器列表”:{ “生产”: [ ">0.2%", “没死”, “不是所有的 op_mini” ], “发展”: [ “最后 1 个 chrome 版本”, “最后 1 个 Firefox 版本”, “最后 1 个 Safari 版本” ] }, "devDependencies": { "@babel/plugin-proposal-export-default-from": "^7.8.3", "css-loader": "^3.4.2" } }

【问题讨论】:

  • 哪个版本的反应你使用..希望你使用大于 16.7.0 alpha(或 16.8 和+)
  • “反应”:“^16.12.0”,

标签: reactjs i18next react-i18next


【解决方案1】:
npm install react-i18next i18next --save

yarn add react-i18next i18next 

【讨论】:

    【解决方案2】:

    已删除 package.jsoni18next 的条目。
    删除了所有 node_modules 文件夹
    重装npm install
    npm install react-i18next i18next --save // 当喜欢检测用户语言并加载翻译时
    npm install i18next-http-backend i18next-browser-languagedetector --save

    这解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-23
      • 2019-06-06
      • 2019-10-24
      • 2021-10-20
      • 2019-12-19
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多