Giter VIP home page Giter VIP logo

Comments (14)

hyochan avatar hyochan commented on June 2, 2024 1

@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.

Below is the screenshot.
Screenshot 2023-07-26 at 2 35 58 PM

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.

hyochan avatar hyochan commented on June 2, 2024 1

@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

Screenshot 2023-07-26 at 3 57 35 PM

from express-rate-limit.

hyochan avatar hyochan commented on June 2, 2024 1

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.

nfriedly avatar nfriedly commented on June 2, 2024

Can you show me what your code looks like for the import statement?

from express-rate-limit.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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'
  • Can you show me your command for compiling the TypeScript to JavaScript? (Probably a build or compile line in the scripts section of your package.json)
    • If you're not using tsc to compile, can you tell me the version of the compiler you are using?

from express-rate-limit.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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.

hyochan avatar hyochan commented on June 2, 2024

@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.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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.

nfriedly avatar nfriedly commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.