我正在使用 React Native EXPO。
我遇到以下错误并需要帮助来解决它:
iOS Bundling failed 14746ms (index.js) Unable to resolve "make-plural" from "node_modules/i18n-js/dist/require/Pluralization.js"
我按照Expo文档安装了expo-localization和i18n-js,并将它们导入到我的App.js中,如下所示:
import * as Localization from 'expo-localization';
import I18n from 'i18n-js';
但是,我在构建过程中仍然遇到上述错误。
metro.config.js
将“mjs”添加到sourceExts。
const { getDefaultConfig } = require('@expo/metro-config')
const path = require('path')
const exclusionList = require('metro-config/src/defaults/exclusionList')
const extraNodeModules = {
shared: path.resolve(__dirname + '/../shared')
}
const watchFolders = [
path.resolve(__dirname + '/../shared')
]
const defaultConfig = getDefaultConfig(__dirname)
const config = {
...defaultConfig,
transformer: {
...defaultConfig.transformer,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
},
resolver: {
...defaultConfig.resolver,
sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs', 'json', 'mjs'],
blockList: exclusionList([/#current-cloud-backend\/.*/]),
extraNodeModules
},
watchFolders
}
module.exports = config