1

I want to render simple svg on Expo, but the below error code is shown.

Uncaught Error: ReferenceError: Can't find variable: React

My code:

import * as React from 'react';
import { Component } from 'react';
import { View, Text} from 'react-native';
import Svg, { Circle, Rect } from 'react-native-svg';

export default class Chart extends Component {
    render() {
        return (
            <View>
                <Svg height="20" width="20">
                <Circle cx="10" cy="10" r="10" fill="red" />
                </Svg>
            </View>
        );
    }
}

My dependencies are as below.

Expo cli: 3.27.4
"expo": "~37.0.3",
"react": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-svg": "11.0.1",

Please advise if you know how to solve this issue. Thanks!

sauceishere
  • 326
  • 5
  • 15
  • the code you provided works as expected: https://snack.expo.io/@notbrent/frowning-popcorn you are probably importing this from another file where you render a react component but don't import react – brentvatne Sep 11 '20 at 01:16
  • @brentvatne Thanks, but I don't really understand "you are probably importing this from another file where you render a react component but don't import react". Can you advise if there is any examples? – sauceishere Sep 11 '20 at 07:16
  • 1
    you may have some other source file where you import the "Chart" component and then render it, but in that file you don't import React – brentvatne Sep 11 '20 at 18:06
  • @brentvatne Thanks, but It did not work. – sauceishere Sep 11 '20 at 23:40
  • the code you have provided is insufficient to help you any further unfortunately. please refer to https://stackoverflow.com/help/mcve for more information on how you can get more help here – brentvatne Sep 14 '20 at 20:25

1 Answers1

0

Try to delete the node_modules and do and npx expo install or yarn install and check if this works.

Giuseppe Nucara
  • 242
  • 1
  • 4