react-i18next icon indicating copy to clipboard operation
react-i18next copied to clipboard

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

Open jvictor98 opened this issue 1 year ago • 1 comments

🐛 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

jvictor98 avatar Aug 26 '24 23:08 jvictor98

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.

anniewey avatar Aug 28 '24 13:08 anniewey

@VIKTORVAV99 here another one ;-)

adrai avatar Aug 29 '24 15:08 adrai

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.

VIKTORVAV99 avatar Aug 30 '24 10:08 VIKTORVAV99

Got fixed by downgrading to v14.1.3

pariharkaran avatar Sep 19 '24 12:09 pariharkaran

@anniewey @pariharkaran did you try v15.0.3 ?

adrai avatar Oct 13 '24 15:10 adrai

@adrai din try v15.0.3 but i managed to get past the error using v15.0.2

anniewey avatar Oct 14 '24 02:10 anniewey

@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 avatar Oct 14 '24 05:10 adrai

@adrai i only updated the version and the error disappears

anniewey avatar Oct 16 '24 04:10 anniewey