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

require-Issue with Node.js 22.12 #481

Open
LukasFritzeDev opened this issue Dec 4, 2024 · 0 comments
Open

require-Issue with Node.js 22.12 #481

LukasFritzeDev opened this issue Dec 4, 2024 · 0 comments

Comments

@LukasFritzeDev
Copy link

Starting today we got the following error when executing our test pipeline:

TypeError: Jest: Got error running globalSetup - /builds/repository/node_modules/@shelf/jest-mongodb/lib/setup.js, reason: Cannot read properties of undefined (reading 'replSet')

We were able to track down the issue to the new Node.js Version v22.12 which changed the default behaviour for require().

Support for loading native ES modules using require() had been available on v20.x and v22.x under the command line flag --experimental-require-module, and available by default on v23.x. In this release, it is now no longer behind a flag on v22.x.

Meanwhile this feature can also be disabled using --no-experimental-require-module as a workaround.

The fix is to add this flag when running the test with Node.js 22.12 or higher. (The flag does not lead to errors in older Node versions. Therefore it can be added to most scripts probably.)

Or test command now look like this (using esm and @shelf/jest-mongodb):

yarn node --experimental-vm-modules --no-experimental-require-module $(yarn bin jest) --no-cache --color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant