rhinobase/hono-rate-limiter

bug: Named export 'rateLimiter' not found

eidam opened this issue · 4 comments

Seems like ES Modules imports are not working.

The following code

import { rateLimiter } from "hono-rate-limiter";

const limiter = rateLimiter({
	windowMs: 60 * 1000, // 1 minute
	limit: 20, // Limit each key (from keyGenerator) to 20 requests per `window` (here, per 1 minute)
	standardHeaders: "draft-6", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
	keyGenerator: () => "<unique_key>", // Method to generate custom identifiers for clients, default to IP address
	store: new Store({
		namespace: "example", // your rlimit.com namespace
	}),
});

Results into

import { rateLimiter } from "hono-rate-limiter";
         ^^^^^^^^^^^
SyntaxError: Named export 'rateLimiter' not found. The requested module 'hono-rate-limiter' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'hono-rate-limiter';
const { rateLimiter } = pkg;

Hey, does the new release v0.1.2 resolved this issue for you?

Hey, thank you for taking a look at this! Unfortunately, a new error occurs.

I made a repro on Stackblitz
https://stackblitz.com/edit/rlimit-com-examples-3nhmj4?file=package.json,index.js

Thank you, It should be fixed with the v0.2.0 release

I can confirm it works now, many thanks!!