Amplitude-JavaScript icon indicating copy to clipboard operation
Amplitude-JavaScript copied to clipboard

ReactNative amplitude-js will not work in a non-browser environment.

Open mym0404 opened this issue 5 years ago • 4 comments

The amplitude-js package warns about the environment. I am using React Native.

[Amplitude] amplitude-js will not work in a non-browser environment. If you are planning to add Amplitude to a node environment, please use @amplitude/node

But, the React Native installiation guide page, they are using amplitude-js directly. Is there any problem?

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Environment

  • JS SDK Version: 7.3.3
  • Installation Method: Yarn, React Native
  • Browser and Version or React Native and Device: React Native 0.63.3

mym0404 avatar Dec 08 '20 01:12 mym0404

Same issue. I found this in the code

if (!isBrowserEnv()) {
    utils.log.warn('amplitude-js will not work in a non-browser environment. If you are planning to add Amplitude to a node environment, please use @amplitude/node');
  }

and this

export function isBrowserEnv(): boolean {
  return typeof window === 'object' && window?.document !== undefined;
}

window.document prints as undefined in React Native

looks related to #174 but not sure what the status is on this fix

warning comes from latest MR #321

emachta avatar Dec 13 '20 03:12 emachta

Thanks for reporting this, will take a look at a fix ASAP

jooohhn avatar Dec 14 '20 18:12 jooohhn

It's a false positive warning, amplitude-js should still work in a react-native environment in the meantime while the fix is being done

Solution will involve the BUILD_COMPAT_REACT_NATIVE flag

jooohhn avatar Dec 14 '20 22:12 jooohhn

Any news for this bug ? I am facing the same issue.

SergeWilfried avatar Mar 08 '21 14:03 SergeWilfried