Skip to content

Commit

Permalink
fix: Do not try to load the expo-file-system package on the Web targe…
Browse files Browse the repository at this point in the history
…t since it's not supported (#158)
  • Loading branch information
marandaneto authored Jan 22, 2024
1 parent 50f681d commit 9cb9ec7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion posthog-react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

1. if `react-native-device-info` is available for the Web target, do not set `unknown` for all properties.
1. Do not try to load the `expo-file-system` package on the Web target since it's not supported.
2. if `react-native-device-info` is available for the Web target, do not set `unknown` for all properties.

# 2.10.1 - 2024-01-15

Expand Down
10 changes: 9 additions & 1 deletion posthog-react-native/src/optional/OptionalExpoFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import type ExpoFileSystem from 'expo-file-system'
import { Platform } from 'react-native'

export let OptionalExpoFileSystem: typeof ExpoFileSystem | undefined = undefined

try {
OptionalExpoFileSystem = require('expo-file-system') // No Web support
// do not try to load expo-file-system on web, otherwise it will throw an error
// Error: The method or property expo-file-system.writeAsStringAsync is not available on web
// See https://github.com/PostHog/posthog-js-lite/issues/140
// Once expo-file-system is supported on web, we can remove this try/catch block
// For now, use the react-native-async-storage/async-storage package instead
if (Platform.OS !== 'web') {
OptionalExpoFileSystem = require('expo-file-system') // No Web support
}
} catch (e) {}

0 comments on commit 9cb9ec7

Please sign in to comment.