Error with import { initReactI18next } from "react-i18next"
🐛 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
- runtime version: node v14.20.1 and 16.18.1,
- i18next version: i.e. ^15.0.1",
- os: Windows
- any other relevant information:
- using in React Native, just android, mac looks ok "react": "17.0.2", i18next": "^23.14.0" openjdk-11.0.14.1_1
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.
@VIKTORVAV99 here another one ;-)
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.
Got fixed by downgrading to v14.1.3
@anniewey @pariharkaran did you try v15.0.3 ?
@adrai din try v15.0.3 but i managed to get past the error using v15.0.2
@adrai din try v15.0.3 but i managed to get past the error using
v15.0.2
@anniewey can you describe how you solved it?
@adrai i only updated the version and the error disappears