flipt-io / flipt-client-sdks

Flipt Client-Side Evaluation SDKs
https://www.flipt.io/docs/integration/client
MIT License
14 stars 6 forks source link

[Bug]: Error: Can't resolve 'os' with Storybook v7 #84

Closed dep closed 4 months ago

dep commented 9 months ago

Bug Description

Trying to use the JS SDK as documented here: https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-client-node

I'm getting a JS error:

ERROR in ../../../../node_modules/@flipt-io/flipt-client/dist/index.js 6:11-24
Module not found: Error: Can't resolve 'os' in '/Users/Box/node_modules/@flipt-io/flipt-client/dist'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
    - install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "os": false }

Version Info

v1.34.0

Search

Steps to Reproduce

  1. Install "@flipt-io/flipt-client": "0.0.3",

  2. Setup:

    
    import { FliptEvaluationClient } from '@flipt-io/flipt-client';

// namespace is the first positional argument and is optional here and will have a value of "default" if not specified. // engine_opts is the second positional argument and is also optional, the structure is: // { // "url": "http://localhost:8080", // "update_interval": 120, // "auth_token": "secret" // } // // You can replace the url with where your upstream Flipt instance points to, the update interval for how long you are willing // to wait for updated flag state, and the auth token if your Flipt instance requires it. const fliptEvaluationClient = new FliptEvaluationClient();

const variant = fliptEvaluationClient.evaluateVariant("flag1", "someentity", {"fizz": "buzz"});

console.log(variant);



3. Start Storybook on the app, see error.

### Expected Behavior

App loads

### Additional Context

_No response_
markphelps commented 9 months ago

👋🏻 Hey @dep ! Thanks for raising this issue.

Because we embed the evaluation engine in the Flipt Client Node, and because the engine is OS/Architecture specific, we need the os Node module to determine what the client OS is. This means that currently the flipt-node-client is limited to running in NodeJS environments and not capable of running in the browser.

We're currently looking into how to bundle the evaluation engine via WASM so that we can release a browser compatible client side evaluation library. But until then, we're only capable of supporting Node compatible usecases with this client.

I will update the https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-client-node README and documentation to note this.

markphelps commented 6 months ago

@dep I know its been awhile! but we've finally released a client-side SDK that's compatible with running in the browser (without NodeJS)

https://www.npmjs.com/package/@flipt-io/flipt-client-browser

Mind giving it a try to see if it fixes this issue for you?

dep commented 6 months ago

@markphelps I'll give it a go when I have a few, thanks!