Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expo 49 not supporting i18n-js #1064

Closed
albandum opened this issue Aug 23, 2023 · 6 comments
Closed

expo 49 not supporting i18n-js #1064

albandum opened this issue Aug 23, 2023 · 6 comments

Comments

@albandum
Copy link

Bug

What is the current behavior?

Upgrading to Expo SDK 49 makes i18n-js fail.

Android Bundling failed 1186ms
Unable to resolve "make-plural" from "node_modules/i18n-js/dist/import/Pluralization.js"

Basically the same thing that was mentionned here but the issue is closed

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

module.exports = getDefaultConfig(__dirname);

Yarn v1.22.15
ProductName: macOS
ProductVersion: 12.2.1

"dependencies": {
   "@expo/webpack-config": "^18.1.2",
   "@react-native-async-storage/async-storage": "1.18.2",
   "@react-navigation/native": "^6.1.6",
   "@react-navigation/native-stack": "^6.9.12",
   "expo": "^49.0.8",
   "expo-av": "~13.4.1",
   "expo-dev-client": "~2.4.8",
   "expo-device": "~5.4.0",
   "expo-file-system": "~15.4.3",
   "expo-keep-awake": "~12.3.0",
   "expo-linking": "~5.0.2",
   "expo-localization": "~14.3.0",
   "expo-network": "~5.4.0",
   "expo-notifications": "~0.20.1",
   "expo-secure-store": "~12.3.1",
   "expo-splash-screen": "~0.20.5",
   "expo-status-bar": "~1.6.0",
   "i18n-js": "^4.3.0",
   "react": "18.2.0",
   "react-dom": "18.2.0",
   "react-native": "0.72.4",
   "react-native-autosize-image": "^0.1.3",
   "react-native-flash-message": "^0.4.1",
   "react-native-gesture-handler": "~2.12.0",
   "react-native-get-random-values": "~1.9.0",
   "react-native-purchases": "^6.1.0",
   "react-native-reanimated": "~3.3.0",
   "react-native-reanimated-carousel": "^3.4.0",
   "react-native-safe-area-context": "4.6.3",
   "react-native-screens": "~3.22.0",
   "react-native-snap-carousel": "^3.9.1",
   "react-native-web": "~0.19.6",
   "uuid": "^9.0.0"
 },
@kasaiee
Copy link

kasaiee commented Aug 28, 2023

I have the problem too

@kasaiee
Copy link

kasaiee commented Aug 28, 2023

go to node_modules/i18n-js/dist/import/Pluralization.js and replace the code with the following code:

// import { en } from "make-plural";
export function useMakePlural({ pluralizer, includeZero = true, ordinal = false, }) {
    return function (_i18n, count) {
        return [
            includeZero && count === 0 ? "zero" : "",
            pluralizer(count, ordinal),
        ].filter(Boolean);
    };
}
export const defaultPluralizer = useMakePlural({
    pluralizer: (n: number | string, ord?: boolean) => "one" | "two" | "few" | "other",
    includeZero: true,
});
export class Pluralization {
    constructor(i18n) {
        this.i18n = i18n;
        this.registry = {};
        this.register("default", defaultPluralizer);
    }
    register(locale, pluralizer) {
        this.registry[locale] = pluralizer;
    }
    get(locale) {
        return (this.registry[locale] ||
            this.registry[this.i18n.locale] ||
            this.registry["default"]);
    }
}
//# sourceMappingURL=Pluralization.js.map

it silent the error temporarily

@sebas-deedee
Copy link

Any final solution on this?

@robhogan
Copy link
Contributor

robhogan commented Sep 1, 2023

make-plural relies on support for resolving .mjs extensions, which Metro supports by default but it looks like Expo overrides.

@EvanBacon / @byCedric - .mjs (and .cjs) support is implemented through watcher.additionalExts (here's why), and it seems Expo overrides that to watch env files - with a fresh create-expo-app project I see Metro is being passed:

additionalExts: [ 'env.development.local', 'env.local', 'env.development', 'env' ],

This is overriding Metro's default, so that .mjs and .cjs files aren't crawled or watched:

exports.additionalExts = ['cjs', 'mjs'];

Could Expo add to Metro's defaults instead?

@robhogan
Copy link
Contributor

robhogan commented Sep 1, 2023

Workaround

Add config.watcher.additionalExts.push('mjs', 'cjs'); to your metro.config.js, ie:

// metro.config.js - see https://docs.expo.dev/guides/customizing-metro/#customizing
const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname);

config.watcher.additionalExts.push('mjs', 'cjs');

module.exports = config;

Closing as this issue is specific to Expo's configuration overrides (see above) and needs to be fixed there.

@robhogan robhogan closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2023
@germanmedinasl
Copy link

Following @robhogan 's tip, I replaced the code of metro-config.js: module.exports = require('@expo/metro-config');
to the code shown above. However I still get the same error. Should I place it in the ts file as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants