react-native: Can't find variable Stylesheet after importing it

11,391

You mixed the case, you need to write

const styles = StyleSheet.create({

like you named it when you imported it.

Share:
11,391
Gabriel Garrett
Author by

Gabriel Garrett

Updated on July 20, 2022

Comments

  • Gabriel Garrett
    Gabriel Garrett almost 2 years

    I'm a bit perplexed on what should be a simple fix. I'm running a react-native project on version 0.27.2, and all of my ios.js files successfully import Stylesheet except one.

    The import looks like this:

    import React, {Component} from 'react';
    import {
      AppRegistry,
      StyleSheet,
      ScrollView,
      Text,
      View,
    } from 'react-native';
    
    import {
      Cell,
      CustomCell,
      Section,
      TableView
    } from 'react-native-tableview-simple';
    
    const styles = Stylesheet.create({
      container: {
          backgroundColor: 'rgb(20,25,30)',
        }
      }
    );
    

    The Stylesheet.create({}) function is what ultimately causes the error Can't find variable Stylesheet to be thrown. However, I've declared styles the same way in every other file with the same imports, and those rendered the styles with no error.

    The only thing that's different in this file is that multiple classes have been declared. I'm new to React, so I don't know if this could cause an issue. Does anyone have any idea what could be causing this?