Comments (14)
@nfriedly Sorry for the late response.
The import statement is same import rateLimit from 'express-rate-limit'
.
It is working fine with tsc
. It starts to fail in ts-jest
from 6.7.1
as mentioned above. Not even 6.8.0
.
It is working fine in 6.7.0
Below is my jest config.
import type {JestConfigWithTsJest} from 'ts-jest';
const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.mjs$': '$1',
'^(\\.{1,2}/.*)\\.js$': '$1',
'^(\\.{1,2}/.*)\\.ts$': '$1',
},
testMatch: ['**/tests/**/*.(test).(ts|js)', '**/?(*.)+(spec).ts?(x)'],
setupFilesAfterEnv: ['./tests/testSetup.ts'],
moduleFileExtensions: ['ts', '.mjs', 'json', 'js'],
modulePathIgnorePatterns: [
'<rootDir>/package.json',
'<rootDir>/dist/package.json',
],
testEnvironment: 'jest-environment-node',
transform: {
'^.+\\.m?[tj]sx?$': [
'ts-jest',
{
useESM: true,
tsconfig: 'tsconfig.json',
},
],
},
// ignore below patterns for `jwks-client` pkg
transformIgnorePatterns: [
'node_modules/(?!(jwks-client|node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)',
],
};
export default jestConfig;
from express-rate-limit.
@nfriedly I generated a small reproduction in https://github.com/hyochan/apollo-server-v4-boilerplate.
It fails in hyochan/apollo-server-v4-boilerplate@dc0f471 while it works in hyochan/apollo-server-v4-boilerplate@d7acbfd
from express-rate-limit.
Also, all of the https://github.com/hyochan/apollo-server-v4-boilerplate links give me a 404 - is it perhaps a private repo?
Oh I am sorry! I just made it to public.
Also regarding dts-gen-7, I think I would not have time to check that out 😥
from express-rate-limit.
Can you show me what your code looks like for the import statement?
from express-rate-limit.
Also, I have a theory about what happened - can you check out the dts-gen-7
branch locally and see if it works for you?
I think the commands are going to be something along these lines:
cd ~
git clone https://github.com/express-rate-limit/express-rate-limit.git
cd express-rate-limit
git checkout dts-gen-7
npm install
npm run compile
npm link
cd <directory where your project is>
npm link express-rate-limit
(The npm link
command lets you use a local version of a dependency instead of the one installed from npm - see https://docs.npmjs.com/cli/v9/commands/npm-link for more.)
Once you're done testing the fix, I believe a regular npm install express-rate-limit will undo the link.
from express-rate-limit.
Hey @hyochan were you able to try out the proposed fix? I haven't been able to recreate your issue, so I'm not sure if that PR will make any difference.
I also have a couple of questions:
- Can you show me what your code looks like for the import statement?
- If it has a complete path in your code, you should try changing it to just
import rateLimit from 'express-rate-limit'
- If it has a complete path in your code, you should try changing it to just
- Can you show me your command for compiling the TypeScript to JavaScript? (Probably a
build
orcompile
line in the scripts section of yourpackage.json
)- If you're not using
tsc
to compile, can you tell me the version of the compiler you are using?
- If you're not using
from express-rate-limit.
Hey, thanks for this; I will take a look at your reproduction sometime soon.
Were you able to test it with the dts-gen-7
branch as described in #360 (comment) and, if so, what was the result there?
from express-rate-limit.
Also, all of the https://github.com/hyochan/apollo-server-v4-boilerplate links give me a 404 - is it perhaps a private repo?
from express-rate-limit.
Ok, got the boilerplate example checked out, did a yarn install
, set up a postgres db, configured it in dotenv/test.env
, and fired off the tests with yarn test
. Confirmed that the tests pass on express-rate-limit 6.7.0 and fail on 6.8.0.
I linked checked out the dts-gen-7
express-rate-limit branch and linked it to your example with yarn link ../express-rate-limit
and then re-ran the tests on the commit that was previously failing, and it passed.
So, I think I'm going to merge in dts-gen-7
, reverting our typescript compiler and DTS bundle generator to their previous major versions, ship that as [email protected], backport it to 6.7.2, then re-release the upgrade as [email protected].
I still don't really understand why it's failing, but my guess is that something in ts-jest
is depending on the typescript 4.x output format and the 5.x changes are breaking it.
from express-rate-limit.
Ok, v6.7.2 and v6.8.1 are both now live on npm: https://www.npmjs.com/package/express-rate-limit
I tested each with your boilerplate example and found that each passed. @hyochan can you confirm that one or both of these works for you?
I haven't done the 7.0.0 release; I'll probably do it sometime soon but I'd like to understand the problem a bit better first.
from express-rate-limit.
@nfriedly Thanks for trying out!!
Could you check the https://github.com/hyochan/apollo-server-v4-boilerplate/actions/runs/5665605076/job/15350729465?
Here hyochan/apollo-server-v4-boilerplate@dc0f471 is where it is failing and after downgrading to 6.7.0
it is working again in recent commit hyochan/apollo-server-v4-boilerplate@d7acbfd.
Above ci has the same result as my local machine.
from express-rate-limit.
Hi @hyochan
Yes, I was also able to recreate the issue on my local machine also, same error as https://github.com/hyochan/apollo-server-v4-boilerplate/actions/runs/5665605076/job/15350729465.
express-rate-limit v6.7.2 and v6.8.1 should both avoid the issue, although I don't yet understand the root cause.
from express-rate-limit.
Ok, I just figured out one thing - it says import()
, but it's actually grabbing the .cjs file. That's probably part of the issue.
But, if I switch your app.ts
to using a named import, then the test passes:
- import rateLimit from 'express-rate-limit';
+ import { rateLimit } from 'express-rate-limit';
I don't understand why the default import fails but the named import works. The .cjs file exports like so:
module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit; module.exports.MemoryStore = MemoryStore;
Anything that works with the named rateLimit
export should also work with either the "naked default" one or the "named default" export.
from express-rate-limit.
I know we never got to the root cause here, but since we figured out a workaround and haven't heard anything further, I'm going to to go ahead and close this. Feel free to re-open or file a new ticket if appropriate.
from express-rate-limit.
Related Issues (20)
- ValidationError: The 'X-Forwarded-For' header is set but the Express HOT 2
- I found that this library occasionally works and occasionally doesn't work. HOT 3
- limit is not working , still need to set max HOT 5
- [Question] keyGenerator option HOT 4
- Get Remaining Rate-Limit HOT 3
- ERR_ERL_DOUBLE_COUNT with multiple rate limits HOT 2
- It blocks all IPs instead of blocking each IP HOT 7
- getKey is undefined in Redis Store HOT 9
- Passed options in RateLimitRequestHandler HOT 1
- Install a problem in express5 / express@next HOT 9
- Can't get the correct ip HOT 3
- Ratelimit headers empty while running on Bun v1.0.x HOT 1
- Don't know how to resetKey when user complete captcha HOT 6
- requestWasSuccessful usage doesn't support returning a Promise
- Can't use process.env variables HOT 3
- An option similar to `skip` but which is evaluated after the request has completed HOT 2
- Add Support for Persistent Storage (e.g., Redis) in express-rate-limit HOT 1
- Enhanced Rate Limiting with a retryAfter option and IP Blocking Features for Improved Flexibility HOT 2
- ERR_ERL_CREATED_IN_REQUEST_HANDLER HOT 5
- Allow rate limit configuration dynamic based on request comes in (Saas) HOT 22
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-rate-limit.