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

Jest - Fastify v5 - [email protected] - error in tests from buildCache #1122

Open
javierxbrenes1 opened this issue Nov 4, 2024 · 3 comments

Comments

@javierxbrenes1
Copy link

javierxbrenes1 commented Nov 4, 2024

Hey, we have tried to update our BE app to start using Fastify v5, we had to update to [email protected], but now when we want to run our tests -we use jest- we are getting the following error:

  TypeError: A dynamic import callback was invoked without --experimental-vm-modules

      at buildCache (../node_modules/mercurius/index.js:65:20)
      at Object.<anonymous>.fp.name (../node_modules/mercurius/index.js:71:21)
      at Plugin.Object.<anonymous>.Plugin.exec (../node_modules/avvio/lib/plugin.js:125:28)
      at Boot.Object.<anonymous>.Boot._loadPlugin (../node_modules/avvio/boot.js:432:10)

Seems buildCache does something like const QuickLRU = (await import('quick-lru')).default we know Nodejs supports this, but seems that Jest doesn't like it.

is there any way to deal with this ?

@mcollina
Copy link
Collaborator

mcollina commented Nov 9, 2024

@voxpelli introduced the dependency on quick-lru in #1108. Maybe there is another LRU implementation that we can use that is not an ESM.

Anyhow, I recommend to not use jest, mostly for these kind of issues.

@voxpelli
Copy link
Contributor

voxpelli commented Nov 9, 2024

Yikes, Jest doesn’t support dynamic import of ESM modules?!

One can surely find or make an LRU implementation that behaves like a Map and isn’t an ESM module, but even if one does there is no guarantee that no other dependency of Mercurius suddenly starts using dynamic imports of ESM in their CJS – because that is perfectly fine and not a breaking change to do.

I would say that Jest is the one in the wrong here.

@voxpelli
Copy link
Contributor

voxpelli commented Nov 9, 2024

@javierxbrenes1 Have you tried running the tests with --experimental-vm-modules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants