upstash / ratelimit-js

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

Deno release broken? #29

Closed thorwebdev closed 1 year ago

thorwebdev commented 1 year ago

Trying to use as per docs

import { Ratelimit } from "https://deno.land/x/upstash_ratelimit/mod.ts";

I'm getting

Warning Implicitly using latest version (v0.3.7) for https://deno.land/x/upstash_ratelimit/mod.ts
Download https://deno.land/x/upstash_ratelimit@v0.3.7/mod.ts
worker thread panicked Import 'https://deno.land/x/upstash_ratelimit@v0.3.7/mod.ts' failed, not found.

When using esm.sh

import { Ratelimit } from "https://esm.sh/@upstash/ratelimit@0.3.7";

I get

serving function upstash-redis-ratelimiter
worker thread panicked Uncaught SyntaxError: The requested module 'https://esm.sh/@upstash/ratelimit@0.3.7' does not provide an export named 'Ratelimit'
    at file:///home/deno/functions/upstash-redis-ratelimiter/index.ts:3:10

Any ideas?

thorwebdev commented 1 year ago

My code is here in case helpful: https://github.com/thorwebdev/edgy-edge-functions/pull/2

chronark commented 1 year ago

Thanks @thorwebdev I'm taking a look

chronark commented 1 year ago

@thorwebdev

import x from "https://esm.sh/@upstash/ratelimit"
import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"

const r = new x["Ratelimit"]({
    redis: Redis.fromEnv()
    limiter: x["Ratelimit"].fixedWindow(10, "10 s")
})
console.log(await r.limit("test"))

here's the hack to unblock you I'm going to dig deeper to see why it broke

thorwebdev commented 1 year ago

Can confirm that the workaround works for me, thanks 👍

chronark commented 1 year ago

A less hacky way is this, I have absolutely no idea why esm.sh doesn't work

import { Ratelimit } from "https://cdn.skypack.dev/@upstash/ratelimit@latest"

I'll update our docs with this while we're still waiting for native npm:@upstash/ratelimit support in deno deploy