optimizely/javascript-sdk

TypeError: randomBytes is not a function

ramanaganti opened this issue · 4 comments

What I wanted to do

Want to connect with Optimizely experiments through our code.

**Code : **

const user: OptimizelyUserContext | null =
                this.optimizelyClientInstance.createUserContext(
                    'userId123'
                );
const decisions: {
                [key: string]: OptimizelyDecision;
            } = user?.decideAll() || {};

What actually happened

Uncaught (in promise) TypeError: YC.randomBytes is not a function
    at KC (prod.0ac937eb.js:210:26173)
    at ax (prod.0ac937eb.js:210:27517)
    at Object.uuid (prod.0ac937eb.js:210:39193)
    at a.decisionObj (prod.0ac937eb.js:210:90112)
    at t.sendImpressionEvent (prod.0ac937eb.js:210:90413)
    at t.decide (prod.0ac937eb.js:210:106257)
    at prod.0ac937eb.js:210:107309
    at Array.forEach (<anonymous>)
    at t.decideForKeys (prod.0ac937eb.js:210:107280)
    at t.decideAll (prod.0ac937eb.js:210:107652)

@optimizely/optimizely-sdk version: ^4.9.2

node version: v14

Thanks for reporting your finding @ramanaganti I'll add this to our stand-up meeting to review.

randomBytes looks to be listed in several parts of the package dependency tree.

Have you run npm install to make sure all the deps are in place?
Have you tried wiping out node_modules and then re-running npm install?

(just some off the cuff thoughts while we collab internally)

Thanks.

@mikechu-optimizely Thanks for the quick response. I tried running npm install command but the issue still persists. We are able to get other feature flags in our code without any issues except the feature flag with experiment turned ON. We have created 2 variations in this experiment with one string variable and using Distribution Mode: Manual with 50% traffic each.

We've created internal ticket FSSDK-8981 to review.

One more question: Do you use the official npm repo or do you have a custom artifact hub sitting in your tool chain?

Hello @ramanaganti ! I am trying to reproduce this issue, but everything is working well for me. Here is my sample repository issue_800. I have set up a project as described in this comment. I have tried to reproduce it on both NodeJS and browser, with no luck. Could you please share whether you are getting this issue in Node or browser, and if in browser, then which bundler you are using and with what configuration, or contribute a PR to my repository that reproduces the issue?