statsig-io / react-sdk

An SDK for using Statsig Feature Management and Experimentation platform in React js clients
ISC License
6 stars 6 forks source link

Bugs in sdk #5

Closed Infi-Knight closed 1 year ago

Infi-Knight commented 2 years ago

Hi, I am trying to setup Statsig in our rails app and starting with react sdk v1.15.2. Here is the provider implementation:

import * as React from 'react'
import { StatsigProvider, StatsigUser } from 'statsig-react'

type Props = {
  children: React.ReactNode | React.ReactNode[]
  statsigUser: StatsigUser
}

const StatsigClientKey = 'client-***'

const Statsig = ({ children, statsigUser }: Props): JSX.Element => {

  return (
    <StatsigProvider
      user={statsigUser}
      waitForInitialization={true}
      sdkKey={StatsigClientKey}
    >
      {children}
    </StatsigProvider>
  )
}

export default Statsig

At first, I got this error:

Uncaught ReferenceError: exports is not defined
    at ./node_modules/statsig-js/dist/index.js (index.js:21:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/statsig-react/dist/index.js (index.js:14:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./app/javascript/src/providers/Statsig.tsx (Statsig.tsx:1:1)
    at __webpack_require__ (bootstrap:19:1)

I fixed it by declaring a global exports object. But now I am stuck on this error:

Statsig.js:186 Uncaught (in promise) TypeError: statsig_js_1.StatsigClient is not a constructor
    at Function.<anonymous> (Statsig.js:186:1)
    at step (Statsig.js:141:1)
    at Object.next (Statsig.js:71:1)
    at Statsig.js:43:1
    at new Promise (<anonymous>)
    at ./node_modules/statsig-react/dist/Statsig.js.__awaiter (Statsig.js:22:1)
    at Statsig.initialize (Statsig.js:182:1)
    at StatsigProvider.js:140:1
    at invokePassiveEffectCreate (react-dom.development.js:23313:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3922:1)

Is this an issue with sdk itself? Anything I am missing here?

Infi-Knight commented 2 years ago

I noticed that this sdk and js-client are both using "commonjs" module system. When I created the dist for both projects using "es6" module system and setting "esModuleInterop" to true, the error is gone.

I wonder if these changes can be applied to both the sdks.

tore-statsig commented 2 years ago

Thanks for the report, we can take a look!

Infi-Knight commented 2 years ago

Hi, any updates on the beta releases for these sdks?

tore-statsig commented 2 years ago

Trying out this for now:

https://www.npmjs.com/package/statsig-react/v/1.16.2-beta.0

tore-statsig commented 2 years ago

Fixed in v1.17.0

https://github.com/statsig-io/react-sdk/releases/tag/v1.17.0