Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing SVG image ends up with base64 error in console and the whole site not loads #235

Open
JunekCZ opened this issue Dec 21, 2022 · 1 comment

Comments

@JunekCZ
Copy link

JunekCZ commented Dec 21, 2022

I am trying to place icons into my navigation but I cannot solve the repetitive error coming after all possible solutions from the internet.
Code:

import React from 'react';
import { Button, SafeAreaView, StatusBar, StyleSheet, Text, View, Image } from 'react-native';
import { Link } from 'react-router-native';
import HomeIcon from "../../assets/icons/ico_home.svg";

const Navigation = () => {
    const [height, setHeight] = React.useState(0);
    const y = 20;

    const styles = StyleSheet.create({
        flex: {
            display: 'flex',
            width: '100%',
            height: '100%',
            flexDirection: 'row',
            alignItems: 'flex-start',
            justifyContent: 'flex-start',
            borderRadius: height,
            backgroundColor: '#B3B3B3',
            overflow: 'hidden',
        },
        link: {
            display: 'flex',
            flexDirection: 'row',
            justifyContent: 'center',
            alignContent: 'center',
            width: '50%',
            paddingTop: y,
            paddingBottom: y
        },
        icon: {
            height: y
        }
    });
    return (
        <View style={styles.flex} onLayout={event => setHeight(event.nativeEvent.layout.height)}>
            <HomeIcon />
            <Link to="/" style={styles.link}>
                <Text>Home</Text>
            </Link>
            <Link to="/events" style={styles.link} >
                <Text>About</Text>
            </Link>
        </View>
    )
};

export default Navigation;

So I am importing HomeIcon. Now the error I am getting in the console.
image

Thank you in advance for your reply!
UPDATE
I forget to paste here metro.config.js:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

const { getDefaultConfig } = require('metro-config');

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve('react-native-svg-transformer'),
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: true,
        },
      }),
    },
    resolver: {
      assetExts: assetExts.filter((ext) => ext !== 'svg'),
      sourceExts: [...sourceExts, 'svg'],
    },
  };
})();

Another big edit!
I found out this only not work in the browser. In the android it works!

@JunekCZ
Copy link
Author

JunekCZ commented Dec 23, 2022

I 'solved' my problem with React svgr with just react-native-svg installed. But this is just a solution to my problem and not to this error so I will leave this for the administrators if they would like to close this as solved or leave it for further comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant