Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: undefined is not an object (evaluating '_expo.default.FileSystem')]

I'm trying to import a database file from assets to expo. But it just doesn't work and return me with warning below:

TypeError: undefined is not an object (evaluating '_expo.default.FileSystem')]

I tried many times, if I create a new database it works but if I try to load an existing database from asset it will not work

class Items extends React.Component {
  state = {
    items: null
  };

  componentDidMount = async () => {
    await Expo.FileSystem.downloadAsync(
      Expo.Asset.fromModule(require("./assets/exu-word.db")).uri,
      `${Expo.FileSystem.documentDirectory}SQLite/exu-word.db`
    );

    let db1 = SQLite.openDatabase("exu-word.db");
  };

  render() {

    const { items } = this.state;


    if (items === null || items.length === 0) {
      return null;
    }

    return (
      <View style={styles.sectionContainer}>

        {items.map(({ id, words }) => (
          <TouchableOpacity
            key={id}
            onPress={() => this.props.onPressItem && this.props.onPressItem(id)}
            style={{
              backgroundColor: "#fff",
              borderColor: "#000",
              borderWidth: 1,
              padding: 8
            }}
          >
            <Text style={{ color: "#000" }}>{words}</Text>
          </TouchableOpacity>
        ))}
      </View>
    );
  }

  update() {
    db.transaction(tx => {
      tx.executeSql(
        `select * from WORDS;`,
        [],
        (_, { rows: { _array } }) => this.setState({ items: _array })
      );
    });
  }
}
like image 748
Yit Club Avatar asked Mar 03 '23 13:03

Yit Club


1 Answers

I work with "sdkVersion": "35.0.0". It seems that Expo changed its API. Now you need to install a separate dependency:

npm i --save expo-file-system

And then to import FileSystem object independently for your component:

import * as FileSystem from 'expo-file-system';
like image 125
Roman Avatar answered Mar 10 '23 11:03

Roman