我在尝试运行我的 React Native 应用程序时遇到此错误:
Unable to resolve module missing-asset-registry-path from /Users/user/Desktop/project/node_modules/@react-navigation/elements/lib/commonjs/assets/back-icon.png: missing-asset-registry-path could not be found within the project or in these directories:
node_modules
> 1 | �PNG
2 |
3 |
4 | IHDR`H����IDATx���1��
我有这个版本的 React Native: “反应本机”:“0.73.6”
我认为这个错误是在我的项目中添加 eslint 配置时出现的。我该如何解决这个问题?
有同样的问题,通过这个答案解决了:https://stackoverflow.com/a/78426573/10722284
TLDR - 升级你的
metro.config.js
,它应该可以解决问题!
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
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);