You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目中make-plural模块解析失败问题求助

解决React Native中make-plural模块plurals.mjs不存在的错误

问题原因

make-plural@7.x版本采用了纯ES模块结构,而React Native 0.72对这类模块的路径解析存在兼容问题,同时i18n-js当前版本对make-plural@7.x的导入逻辑不匹配,导致找不到指定的plurals.mjs文件。

解决方案

1. 降级make-plural到兼容版本

卸载当前版本,安装与React Native 0.72及i18n-js兼容的6.x版本:

# npm
npm uninstall make-plural
npm install make-plural@6.4.0

# yarn
yarn remove make-plural
yarn add make-plural@6.4.0

该版本采用CommonJS模块格式,与React Native的模块解析机制完全适配,且i18n-js对其导入逻辑无冲突。

2. 确认i18n-js的pluralization配置

确保i18n初始化时正确导入make-plural的plurals文件,避免根模块导入:

import { I18n } from 'i18n-js';
// 直接指定plurals文件路径,避免模块解析歧义
import pluralize from 'make-plural/plurals';

const i18n = new I18n({
  // 你的本地化配置内容
});

i18n.pluralization = pluralize;

3. 清理缓存并重建项目

完成版本调整后,清理各类缓存确保依赖生效:

# 清除npm/yarn缓存
npm cache clean --force
# 或 yarn cache clean

# 删除依赖目录和锁文件(Windows替换为rmdir /s /q node_modules && del package-lock.json yarn.lock)
rm -rf node_modules package-lock.json yarn.lock

# 重新安装依赖
npm install
# 或 yarn install

# 重置React Native缓存并启动
npx react-native start --reset-cache

之后重新运行npx react-native run-android或npx react-native run-ios即可。

内容的提问来源于stack exchange,提问作者Seique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 07:47:05