React Native 在 build iOS 的时候如果出现关于 metro
的错误, 例如:
Command PhaseScriptExecution failed with a nonzero exit codeShowing Recent Issues
/xxxxxxxxxxxxxxxxx/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:139throw new UnableToResolveError(^
解决方案, 修改 metro.config.js
如下:
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');const defaultConfig = getDefaultConfig(__dirname);const {resolver: {sourceExts, assetExts},
} = getDefaultConfig(__dirname);const config = {transformer: {getTransformOptions: async () => ({transform: {experimentalImportSupport: false,inlineRequires: true,},}),babelTransformerPath: require.resolve('react-native-svg-transformer'),},resolver: {assetExts: assetExts.filter(ext => ext !== 'svg'),sourceExts: [...sourceExts, 'svg'],},
};module.exports = mergeConfig(defaultConfig, config);