Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Importing the @openfeature/launchdarkly-client-provider throws a TypeError #659

Closed
juanparadox opened this issue Nov 7, 2023 · 9 comments · Fixed by #660
Closed
Assignees
Labels
bug Something isn't working

Comments

@juanparadox
Copy link
Member

juanparadox commented Nov 7, 2023

Observed behavior

I installed the @openfeature/web-sdk and @openfeature/launchdarkly-client-provider packages using pnpm install.

Upon trying to simply import the LaunchDarklyClientProvider via import { LaunchDarklyClientProvider } from "@openfeature/launchdarkly-client-provider"; and running my local app (it's the boilerplate Vite React project that the Vite install provides) a TypeError.

open-feature-event-emitter.ts:11 Uncaught TypeError: import_events.default is not a constructor
    at new GenericEventEmitter (open-feature-event-emitter.ts:11:35)
    at new InternalEventEmitter (open-feature-event-emitter.ts:83:8)
    at new OpenFeatureCommonAPI (open-feature.ts:21:30)
    at new OpenFeatureAPI (open-feature.ts:18:5)
    at OpenFeatureAPI.getInstance (open-feature.ts:32:22)
    at open-feature.ts:92:43

Expected Behavior

I expected the provider to be able to be imported without a TypeError being thrown so that it can be instantiated into the OpenFeature.setProvider method.

Steps to reproduce

  1. Install the @openfeature/web-sdk library (This may not be necessary as the issue occurs when just importing the provider library below)
  2. Install the @openfeature/launchdarkly-client-provider library
  3. Create a new file, say featureFlags.ts with the following (this is as bare of code you can write to reproduce the issue, I understand it's not creating a LaunchDarklyClientProvider instance or doing anything with the import, you could skip this step and just import the provider library directly into a file your app is already using)
import { LaunchDarklyClientProvider } from "@openfeature/launchdarkly-client-provider";
  1. Import that file into your app, something like
import './featureFlags';
  1. TypeError is thrown upon running the application
@juanparadox juanparadox added the bug Something isn't working label Nov 7, 2023
@juanparadox
Copy link
Member Author

@toddbaert Just created the issue about the constructor error. Please let me know if you need more details.

@toddbaert
Copy link
Member

Thanks @juanparadox . Can you confirm the versions you're using (I'm assuming both @ latest)?

And are you using yarn or npm? (They behave a bit differently with peer dependencies, which may be related to the problem).

@toddbaert toddbaert self-assigned this Nov 7, 2023
@juanparadox
Copy link
Member Author

@toddbaert Yeah! They are both at the latest versions and I am using pnpm.

@toddbaert
Copy link
Member

@toddbaert Yeah! They are both at the latest versions and I am using pnpm.

I believe pnpm doesn't automatically install peer dependencies. Can you confirm @openfeature/core is installed?

@juanparadox
Copy link
Member Author

@toddbaert I just manually installed @openfeature/core with pnpm and the error still occurs.

@toddbaert
Copy link
Member

@toddbaert I just manually installed @openfeature/core with pnpm and the error still occurs.

Ok thanks again! I'll try to replicate the issue myself and get back to you 🙏

@juanparadox
Copy link
Member Author

Thank you very much!

github-merge-queue bot pushed a commit that referenced this issue Nov 9, 2023
Fixes: #659

This PR fixes an issue created with [this
change](#650), which removed
the `events` polyfill package from `@openfeature/core` where is wasn't
always needed (see that issue for details). The problem was that we
still imported `events` in the `@openfeature/core` module, but can't use
the `events` bundled in the `@openfeature/web-sdk` since the bundled
package there isn't accessible from imports in `@openfeature/core`.

This PR _**removes all imports of `events`**_ from `@openfeature/core`,
and instead only imports types. Imports of `events` only now occur in
the web-sdk (where it's bundled) and server-sdk (where it's made
available by the node runtime), not in the common module.

Unfortunately this issue was a bit tough to track down, because `events`
is VERY common, and lots of bundlers, etc will add it, so it's
frequently available "accidentally".

Thanks to @juanparadox for the report.

---------

Signed-off-by: Todd Baert <[email protected]>
@toddbaert
Copy link
Member

toddbaert commented Nov 9, 2023

@juanparadox fix is released. Please let me know if your problem is resolved (you'll need to update core and web sdk)

@juanparadox
Copy link
Member Author

@toddbaert Fix looks to have worked! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants