launchdarkly/react-native-client-sdk

Does react-native-client-sdk (v10) support expo web?

Opened this issue · 5 comments

Describe the bug
We have an expo project that we are targeting both mobile and web platforms. The react-native-client-sdk works well on mobile but crashes in web.

This is the error I see:

autoEnv.js:24 Uncaught TypeError: Cannot read properties of undefined (reading 'Manufacturer')

which traces to this code in autoEnv, seems like Platform.constants is undefined somehow.

export const ldDevice = {
    // key is populated by common/client-sdk
    key: '',
    envAttributesVersion: '1.0',
    manufacturer: Platform.select({
        ios: 'apple',
        android: Platform.constants.Manufacturer,
    }),
    model: Platform.select({
        // ios: model n/a from PlatformIOSStatic
        android: Platform.constants.Model,
    }),
    os: {
        family: Platform.select({
            ios: 'apple',
            default: Platform.OS,
        }),
        name: Platform.OS,
        version: (_a = Platform.Version) === null || _a === void 0 ? void 0 : _a.toString(),
    },
};

To reproduce
Follow the SDK doc to initialize LD client and identify user.

Expected behavior
Expect react-native-client-sdk to work on all platforms expo support (Android, IOS, web)

SDK version
10.1.3

OS/platform
Web browser: Chrome Version 124.0.6367.62

Any insights are greatly appreciated, thank you!

Hello @QuanGao-osmind, we will look into turning off autoEnv for the web (Filed internally as 242760). In the meantime, while it is extra effort and trouble for you, I wonder if disabling autoEnv when you build for the web platform could work?

Also, if you don't mind, could you post this to https://github.com/launchdarkly/js-core? That is where the RN SDK v10 (and beyond) lives.

Hello @louis-launchdarkly thank you for the reply!
We end up adding a patch for the package to prevent it from crashing on web. Now we are seeing a CORS issue since there's no CORS headers served on mobile endpoint. (After disabling browser security, it works as expected)

I will post issues related to react-native-client-sdk to the other repo you suggested!

Hello @louis-launchdarkly thank you for the reply! We end up adding a patch for the package to prevent it from crashing on web. Now we are seeing a CORS issue since there's no CORS headers served on mobile endpoint. (After disabling browser security, it works as expected)

I will post issues related to react-native-client-sdk to the other repo you suggested!

What was the fix?

@wahidshafique We had to install two SDKs, LD React SDK for web, and LD React-native SDK for IOS and Android.