upstash / ratelimit-js

Rate limiting library for serverless runtimes
https://ratelimit-with-upstash.vercel.app/
MIT License
1.73k stars 33 forks source link

Crypto is not properly imported #20

Closed jasonsilberman closed 1 year ago

jasonsilberman commented 1 year ago

When I am trying to use the MultiRegionRatelimit rate limiter, I am getting the following error:

ReferenceError: crypto is not defined
    at MultiRegionRatelimit.limiter (/Users/jason/WORK/llegamus/node_modules/@upstash/ratelimit/script/multi.js:94:31)
    at MultiRegionRatelimit.value (/Users/jason/WORK/llegamus/node_modules/@upstash/ratelimit/script/ratelimit.js:65:35)

This is because the crypto package is not imported before it is used during the multi region rate limiter. I think this is likely because Deno automatically imports the module, where other node runtimes do not.

I tried manually patching the package locally to import crypto and everything worked fine.

My specific setup is using Remix Dev Server and then hosting on Vercel's Serverless Functions. I don't think Vercel's Edge Functions would have this issue as it seems like they have support for the Web Crypto APIs.

chronark commented 1 year ago

Fixed in v0.2.0