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

Cloudflare worker Uncaught ReferenceError: FinalizationRegistry is not defined #92

Open
TranquilMarmot opened this issue Feb 13, 2024 · 1 comment

Comments

@TranquilMarmot
Copy link

TranquilMarmot commented Feb 13, 2024

This is a duplicate of #46 but that's closed, and I don't think it should be 😄

Following the instructions here in the README:

https://github.com/dqbd/tiktoken?tab=readme-ov-file#cloudflare-workers

When you try to deploy the function to Cloudflare, it will fail with:

Uncaught ReferenceError: FinalizationRegistry is not defined

It's happening at:

node_modules/.pnpm/[email protected]/node_modules/tiktoken/lite/tiktoken_bg.js:167:30

Using js-tiktoken here isn't an option since the package for a Cloudflare worker has to be < 1MiB (1024 KiB) after gzip, so WASM is really the only route to go if you want to run this in a Cloudflare worker.

Note; you can use gpt-tokenizer in a Cloudflare worker with something like:

const myFunction = async () => {
   const { encode, decode } = await import("gpt-tokenizer");
   // ... can use functions here, but the overall bundle size is still small
}

It seems like the Cloudflare worker instructions should be removed from the README for now, or at the very least the ✅ should be changed to a ❌.

@RBSUS
Copy link

RBSUS commented Feb 14, 2024

I came across this today. It's preventing me from deploying my NodeJs API. As far as I'm aware, I didn't update this package and yet the error has come about out of thin air. Therefore, this may be something to do with the Google Cloud Functions environment in which I'm running the api. Currently assessing older versions of this package to see if the error persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants