Expo SDK 37 ejection breaks AsyncStorage from SDK 36

I have been using AsyncStorage, imported from ‘react-native’, to store some local data. I recently upgraded from SDK 36 ExpoKit -> SDK 37 ejected into the bare workflow.

Now, AsyncStorage seems to no longer be working as expected. Upon uploading the build to TestFlight and updating the app, all of the stored data goes away. However, when I downgrade back to the previous version (the ExpoKit SDK 36 app), the data loads back in perfectly fine.

This makes me think that the storage directory is somehow changed during the upgrade to SDK 37 bare workflow. Is this true, and how can I fix this?

I was finally able to get it working. It turns out that the storage directory did change. The old directory was: RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage/manifest.json'. The new directory is RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1/manifest.json'.

To migrate the data, I had to get the contents of manifest.json from the old location, parse the response, then loop through the keys in the object and use AsyncStorage.setItem for all of the keys.

1 Like

Thanks for enlightening us, I’m facing the same issue and I wonder if you have a snippet to share, would save us a lot of time.

This has worked for me, however this is only valid for iOS …

    // read the documentDir directory
    const docDir = await FileSystem.readDirectoryAsync(`${FileSystem.documentDirectory}`)
    
    // check if legacy local storage is there (from Expokit) and read it
    if (docDir.length !== 0 && docDir.includes('RCTAsyncLocalStorage')) {
      const manifest = await FileSystem.readAsStringAsync(
        `${FileSystem.documentDirectory}/RCTAsyncLocalStorage/manifest.json`
      )

      //   Loop through keys-values and add them to actual AsyncStorage
      const entries = Object.entries(JSON.parse(manifest))
      for (const [key, value] of entries) {
        try {
          console.log(`Setting ${key} to ${value} `)
          await AsyncStorage.setItem(key, value)
        } catch (error) {
          // Error saving data
        }
      }
    }

And here how it was fixed for me on Android https://gist.github.com/luizjr92/db091719f09617abc5909ba64485e395