barvian / number-flow

A component to transition, format, and localize numbers.
https://number-flow.barvian.me
MIT License
4.71k stars 76 forks source link

`esm-env` exports resolution issue in Cloudflare Pages environment #45

Closed NOBLES5E closed 1 month ago

NOBLES5E commented 1 month ago

There's currently an issue with esm-env package's exports resolution when running in Cloudflare Pages environment. The problem stems from Cloudflare Pages being treated as a WebWorker environment, which Vite considers as a browser environment. This causes server-side code to incorrectly use browser exports.

barvian commented 1 month ago

Hi, thanks for filing this 👋. I just pushed @number-flow/react@0.2.4 with an attempted fix. Please comment if you'e still experiencing issues!

barvian commented 4 weeks ago

@NOBLES5E do you have a link to an issue on Cloudflare/esm-env/Vite for this by chance? I couldn't find anything and it'd be nice to know if it gets resolved 👋

NOBLES5E commented 4 weeks ago

Yes, it is resolved. We use it in an internal project, so no issues can be found on GitHub.

Thank you for the quick fix!

barvian commented 4 weeks ago

Oh, great to hear! I was actually wondering if you had a link to an upstream issue for esm-env on Cloudflare Pages? It sounds like a bug on Cloudflare Pages and I'd like to switch back to esm-env at some point 😄

barvian commented 2 weeks ago

I just reverted to using esm-env because it's better for tree-shaking, so in case you upgrade and are still experiencing issues you should be able to add this to your package.json:

"overrides": {
    "esm-env": "npm:esm-env-runtime@^0.1.0"
}

Please let me know if you're still experiencing issues 👋

NOBLES5E commented 2 weeks ago

@barvian The issue is occurring again after upgrading. I'm getting the following error:

06:47:02 [ERROR] ReferenceError: HTMLElement is not defined
    at chunks/index_BVeMng_S.mjs:2:18862

I tried adding the suggested override to package.json:

"overrides": {
    "esm-env": "npm:esm-env-runtime@^0.1.0"
}

However, this doesn't resolve the HTMLElement reference error.

barvian commented 2 weeks ago

@NOBLES5E Hi, could you try esm-env-runtime@^0.1.1 now?

NOBLES5E commented 2 weeks ago

Everything is working properly now. Really appreciate the quick responses and fixes.