metro: Transformer for asset does not work
Do you want to request a feature or report a bug? Bug
What is the current behavior? I am trying to create a transformer that process .svg files. Currently it only feed .js files to the transformer not .svg files
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
- yarn install
- react-native run-ios / react-native run android
- check metro packager log for .svg file (console.log from transformer. see svg_transformer)
Minimal repository: https://github.com/kruyvanna/metro-asset-transformer-test
What is the expected behavior? transformer.transform get called with .svg file
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system. i have rn-cli.config.js with the following content
module.exports = {
assetTransforms: true,
getPlatforms: () => ["ios", "android"],
getTransformModulePath() {
return require.resolve('./svg_transformer')
},
getAssetExts() {
return ["svg"];
}
};
node: v8.9.1 yarn: 1.7.0 npm: 5.6.0 react-native-cli: 2.0.1 react-native: 0.55.4
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 29 (6 by maintainers)
@idudinov @fdagostino the docs for
react-native-svg-transformerhave been updated to include the correct config for expo-cli 3.x https://github.com/kristerkari/react-native-svg-transformer#for-react-native-v057-or-newer--expo-sdk-v3100-or-newerI managed to get the
.svgimages to load in React Native!The config to do that is very verbose because I also need to modify
assetExtsno to includesvgfile extension:That’s pretty difficult to understand for someone who is not familiar with Metro at all.
Phew! Downgrading XCode did not help, but downgrading Expo CLI did. Replaced
3.0.xwith2.21.2and the problem has gone. Spent only a day to work around this! 😂Hi @sometimescasey!
Thank you very much! It works! I have tried this in the past, but I think I omitted ‘jpg’ and since I know it was a default asset extension I just tried to extend the config as others have done before. But this is ok and since it works it is all I need.
Would it be possible to have some config property that would just add the file extension to the default ones instead of replacing them?
Would be great to keep the config as simple as my previous example:
I’m having problems to get the new Metro configuration to work.
I have been trying out the 0.57.0-rc.2 version of React Native, which also includes the new Metro config. I’m using a working 0.56.0 project as the base.
I’ve read the code changes from React Native’s side and the updated docs for Metro, and based on that my updated
rn-cli.config.jsfor transforming SVG files looks like this:The new config however just makes Metro throw an error:
@rafeca do you have any ideas why that might happen?
Yes, they fix it