Skip to content

Not able to run unleash on cloudflare workers (v8) #725

Closed

Description

@exophunk

Describe the feature request

I want to use unleash together with Gitlab Feature Flags (in a Vue Nuxt.js application). Therefore i created a serverside endpoint in our nuxt app (nuxt runs a nitro server) that uses unleash-client. Everything works flawlessly local.

When I try to deploy it to our Cloudflare pages, the deployment fails with:

Error: Failed to publish your Function. Got error: Uncaught TypeError: Class extends value #<Object> is not a constructor or null
  at chunks/nitro/nitro.mjs:1:222837

I think the reason is that Cloudflare workers run on V8 and not Node.js. Apparently unleash-client relies on some node API's that V8 does not provide and therefore it doesn't work.

Ofc this is not a bug from your side, but I wonder if there is a way to polyfill/fix this or is there another unleash approach to cloudflare?

Or is it impossible to use Unleash together with Cloudflare?

Background

No response

Solution suggestions

No response

Activity

  1. Tymek commented on Apr 16, 2025

    @Tymek
    Contributor

    From prior investigations, IP and Hostname strategies are an issue here. I'll try to investigate if we can import relevant dependencies conditionally.

  2. self-assigned this
    on Apr 25, 2025
  3. moved this from New to Investigating in Issues and PRson Apr 29, 2025
  4. gastonfournier commented on Jun 16, 2025

    @gastonfournier
    Contributor

    Hi, @exophunk it should be possible, but it requires some refactoring. Right now this is not top of our priority list. If you'd like to contribute with a PR we'll happily review it. Maybe (just maybe), you'll have to fork this repo and create a cloudflare specific client.

    I'm not familiar with pollyfill, but sounds like a way of replacing those v8 functions with other specific functions of the target platform (such as clouflare) at compilation time.

    Ideally, we should start by identifying the issues. I believe some common culprits of this issue are:

    1. Imports: require('fs'), require('net'), require('stream'). From a quick search in our codebase fs is used for caching and bootstrapping, and likely 'net' is needed for the strategies mentioned by Tymek.
    2. Use of process: we use it for environment variables (mostly)

    But this is just a short list I spent 10' on.

  5. moved this from Investigating to For later in Issues and PRson Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions