open-feature / js-sdk-contrib

OpenFeature Providers and Hooks for JavaScript
https://openfeature.dev
Apache License 2.0
35 stars 36 forks source link

Bug/Question: Flipt Provider: Uncaught TypeError: import_events.EventEmitter is not a constructor #868

Closed markphelps closed 5 months ago

markphelps commented 5 months ago

From our Discord: https://discord.com/channels/960634591000014878/1227377993513439372/1227377993513439372

A user is trying to use the Flipt OpenFeature JS provider in their Vue2/Vite front-end code.

When they import the provider lib :

// main.js
// ... other imports
import { FliptProvider } from '@openfeature/flipt-provider'

and run Vite, they end up with the following error in their dev console:

@openfeature_flipt-p…r.js?v=ffb64f91:838 Uncaught TypeError: import_events.EventEmitter is not a constructor
    at new OpenFeatureEventEmitter (@openfeature_flipt-p…s?v=ffb64f91:838:41)
    at new _OpenFeatureAPI (@openfeature_flipt-p…s?v=ffb64f91:887:40)
    at _OpenFeatureAPI.getInstance (@openfeature_flipt-p…s?v=ffb64f91:903:22)
    at @openfeature_flipt-p…s?v=ffb64f91:966:34

dependencies installed:

    "@openfeature/flipt-provider": "^0.1.0",
    "@openfeature/server-sdk": "^1.13.4",

Did we not implement something correctly in the Flipt Server Provider?

avi-ran commented 5 months ago

hi everyone ! 🙂

Short follow up on the topic: it seems like the flipt provider is not built to be used on a "browser" environment (as it relies on open-feature/server-sdk).

My resulting question is the following one: Is it planned to have a provider version based on openfeature/web-sdk instead of open-feature/server-sdk ? This would probably solve my issue if it is the case.

Have a nice day! Aviran

beeme1mr commented 5 months ago

Hey @avi-ran, yes that's the issue. In this case, the web SDK has a polyfill that simulates the eventing library in Node. It's worth noting that the web and server SDKs work fundamentally differently. You can read about it here.

Perhaps @markphelps could speak on any plans of creating a web provider. Perhaps Flipt would also be interested in adding support for the OpenFeature Remote Evaluation Protocol.

markphelps commented 5 months ago

Hey @beeme1mr ! Yes I think we can definitely create an openfeature/web-sdk now as we just released our browser SDK

@avi-ran would you be interested in helping us create ^? if not no worries, just figured it might be nice to have someone who knows javascript/typescript better than me ;)

markphelps commented 5 months ago

Also, @beeme1mr . I'd love to chat with you about OFREP at some point as im not sure I fully understand it yet

beeme1mr commented 5 months ago

@markphelps sure, that would be great. I think OFREP would work well in Flipt. In a nutshell, it's an open api definition and provider implementations. That means you wouldn't need to build and maintain providers to have great OpenFeature support. This is especially useful for web and mobile use cases.

markphelps commented 5 months ago

@avi-ran i pushed up the initial scaffolding of the OF flipt-web provider here: https://github.com/flipt-io/js-sdk-contrib/compare/main...flipt-io:js-sdk-contrib:flipt-web?expand=1

Now just need to implement it ;)

markphelps commented 5 months ago

@avi-ran I have a PR up for the open feature Flipt web provider here: https://github.com/open-feature/js-sdk-contrib/pull/879