i18next / react-i18next

Internationalization for react done right. Using the i18next i18n ecosystem.
https://react.i18next.com
MIT License
9.21k stars 1.02k forks source link

Error with import { initReactI18next } from "react-i18next" #1797

Open jvictor98 opened 2 weeks ago

jvictor98 commented 2 weeks ago

🐛 Bug Report

Error with import { initReactI18next } from "react-i18next"; Whenever I refer (Import {Initreacti18Next} from "React-i18Next";) The following error appears "Unexpect token '?'". .The same happens if I refer to (Import {Usetranslation} from 'React-i18Next';). I tried everything, clean cache, node, and even started another project and this mistake does not disappear, someone Can you help me?

To Reproduce

React Native

import pt from "./pt.json";
import en from "./en.json";
import i18n from 'i18next';
import { initReactI18next } from "react-i18next";

i18n.use(initReactI18next).init({
    compatibilityJSON: 'v3',
    lng: 'en',
    resources: {
        en: en,
        pt: pt
    },
    react: {
        useSuspense: false,
    },
    interpolation: {
        escapeValue: false
    }
})

export default i18n;

Expected behavior

A clear and concise description of what you expected to happen.

// Paste the expected results here

Your Environment

anniewey commented 2 weeks ago

Facing same issue, getting errors at launch. Only occur in Android, iOS was fine.

error node_modules/react-i18next/dist/commonjs/context.js: Unexpected token: operator (?) in file node_modules/react-i18next/dist/commonjs/context.js at 56:36.
Error: Unexpected token: operator (?) in file node_modules/react-i18next/dist/commonjs/context.js at 56:36

Notice that nullish coalescing was introduced in v15.0.0, hence downgrading to version below it (v14.1.3) solves the issue. @jvictor98 can use v14 temp while wait for the fixes.

adrai commented 2 weeks ago

@VIKTORVAV99 here another one ;-)

VIKTORVAV99 commented 2 weeks ago

I would recommend that everyone that needs to support a specific device or set of devices do so by configuring their build tool so it transforms or transpiles the code so it's compatible with that device.

It's unreasonable to expect that packages stick with obsolete syntax when it would only affect a tiny subset of the users.