簡體   English   中英

React js i18n Uncaught SyntaxError:意外的令牌'導出'

[英]React js i18n Uncaught SyntaxError: Unexpected token 'export'

我得到以下問題:

Uncaught SyntaxError: Unexpected token 'export'

文件index.js:

import configureI18n from './i18n/i18n';

當我嘗試導入以下文件時,它開始停止工作,這給我帶來了問題。

文件./i18n/i18n.js:

import i18n from 'i18next';
import { reactI18nextModule } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import ReduxDetector from 'i18next-redux-languagedetector';
import Backend from 'i18next-chained-backend';
import Fetch from 'i18next-fetch-backend';

const Detector = new LanguageDetector();
Detector.addDetector(ReduxDetector);

export default function configureI18n({ i18nextConfig, redux }) {
  i18n
    .use(Backend)
    .use(Detector)
    .use(reactI18nextModule)
    .init({
      backend: {
        backends: [Fetch],
        backendOptions: [
          {
            loadPath: '/locales/{{lng}}/{{ns}}.json'
          }
        ]
      },
      detection: {
        order: ['navigator'],
        lookupRedux: redux.lookupRedux,
        cacheUserLanguageRedux: redux.cacheUserLanguageRedux,
        caches: ['redux'],
        excludeCacheFor: ['cimode']
      },
      whitelist: i18nextConfig.whitelist,
      fallbackLng: i18nextConfig.fallbackLng,
      ns: i18nextConfig.ns,
      defaultNS: i18nextConfig.defaultNS,
      debug: process.env.NODE_ENV !== 'production',
      interpolation: {
        escapeValue: false
      },
      react: {
        wait: false
      },
      nonExplicitWhitelist: true,
      load: 'currentOnly'
    });

  return i18n;
}

你能給我一些建議嗎? 我在哪里做錯了。

嘗試在大括號中返回i18n

return{
  i18n
    .use(Backend)
    .use(Detector)
    .use(reactI18nextModule)
    .init({
      backend: {
        backends: [Fetch],
        backendOptions: [
          {
            loadPath: '/locales/{{lng}}/{{ns}}.json'
          }
        ]
      },
      detection: {
        order: ['navigator'],
        lookupRedux: redux.lookupRedux,
        cacheUserLanguageRedux: redux.cacheUserLanguageRedux,
        caches: ['redux'],
        excludeCacheFor: ['cimode']
      },
      whitelist: i18nextConfig.whitelist,
      fallbackLng: i18nextConfig.fallbackLng,
      ns: i18nextConfig.ns,
      defaultNS: i18nextConfig.defaultNS,
      debug: process.env.NODE_ENV !== 'production',
      interpolation: {
        escapeValue: false
      },
      react: {
        wait: false
      },
      nonExplicitWhitelist: true,
      load: 'currentOnly'
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM