Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'express-rate-limit' does not provide an export named 'default' when running with jest with --experimental-vm-modules #267

Closed
soruly opened this issue Dec 25, 2021 · 4 comments
Labels
bug A bug in the library typescript Related to typescript

Comments

@soruly
Copy link

soruly commented Dec 25, 2021

Description

$ npm run jest

> trace.moe-api@1.0.0 jest
> NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules jest --runInBand

Determining test suites to run...
 FAIL  src/get-status.test.js
  ● Test suite failed to run

    SyntaxError: The requested module 'express-rate-limit' does not provide an export named 'default'

      at Runtime.linkAndEvaluateModule (node_modules/jest-runtime/build/index.js:779:5)

This has been working for express-rate-limit@5.5.1 with nodejs and jest, and working with 6.0.0 with nodejs, but not with jest

Maybe jest (27.4.5) doesn't fully support ESM yet. Running with node is perfectly fine.

This test are written in ESM and requires --experimental-vm-modules to run with jest, because it doesn't transpile anything with babel.

The test case: https://github.com/soruly/trace.moe-api/blob/master/src/app.js

Library version

6.0.0

Node version

v16.13.0

Typescript version (if you are using it)

No response

Module system

ESM

@soruly soruly added the bug A bug in the library label Dec 25, 2021
@gamemaker1
Copy link
Member

Hi @soruly,

This is a known issue with Jest (it does not support the exports field in package.json). A similar issue exists on the Jest repo - jestjs/jest#11742).

There is a PR to fix it that might be part of Jest v28, but until then you can use the workaround described here (basically, just delete the main field from node_modules/express-rate-limit/package.json before running the test and restore it after).

Hope this helps.

@soruly
Copy link
Author

soruly commented Dec 25, 2021

Thanks, I'll stay in old version until then ;)

@gamemaker1
Copy link
Member

Hi @soruly,

Could you try running these tests again with v6.0.1 - they seem to run fine in this example project.

Thanks!

@soruly
Copy link
Author

soruly commented Dec 25, 2021

Hi @gamemaker1

Confirmed working with v6.0.1 without any modifications, thanks :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the library typescript Related to typescript
Projects
None yet
Development

No branches or pull requests

2 participants