fnando / i18n-js

It's a small library to provide the I18n translations on the Javascript. It comes with Rails support.
MIT License
3.77k stars 520 forks source link

Bug: Require cycles are allowed, but can .... #657

Closed lvlrSajjad closed 1 year ago

lvlrSajjad commented 2 years ago

Description

I use this library in my react-native project. After upgrading to 4.0.2 I get these warning.

 WARN  Require cycle: node_modules/i18n-js/dist/import/helpers/index.js -> node_modules/i18n-js/dist/import/helpers/numberToHumanSize.js -> node_modules/i18n-js/dist/import/helpers/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: node_modules/i18n-js/dist/import/helpers/index.js -> node_modules/i18n-js/dist/import/helpers/pluralize.js -> node_modules/i18n-js/dist/import/helpers/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: node_modules/i18n-js/dist/import/helpers/index.js -> node_modules/i18n-js/dist/import/helpers/roundNumber.js -> node_modules/i18n-js/dist/import/helpers/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: node_modules/i18n-js/dist/import/helpers/index.js -> node_modules/i18n-js/dist/import/helpers/timeAgoInWords.js -> node_modules/i18n-js/dist/import/helpers/index.js

How to reproduce

install version 4.0.2 and use it this way:

import * as Localization from "expo-localization"
import { I18n } from "i18n-js"
import en from "./en_us.json"
import es from "./es_mx.json"
import fr from "./fr_ca.json"

export const i18n = new I18n({ en, es, fr }, {
  enableFallback: true,
  defaultLocale: Localization.locale || "en"
});

export const switchLocale = (code: string) => {
  i18n.locale = code
}
fnando commented 2 years ago

Hi, @lvlrSajjad. Can you please upload a sample app reproducing this issue? Thanks!

fnando commented 2 years ago

Hey! I couldn't reproduce these warnings. Here's the app I tried: foo.zip

Can you please give it a try and let me know if it seems okay? The only difference is that I didn't import expo-localization.

codeion commented 2 years ago

Warnings are there, you can quickly check it with metro-plugin-cyclic-dependencies-detector

warn i18n-js/dist/import/helpers/index.js warn └── i18n-js/dist/import/helpers/timeAgoInWords.js warn └── i18n-js/dist/import/helpers/index.js warn └── i18n-js/dist/import/MissingTranslation.js

fnando commented 1 year ago

I believe this issue has been fixed by https://github.com/fnando/i18n/pull/35.

Can you please try the latest version and see if fixes it? I'll close this issue for now.