Skip to content

require-Issue with Node.js 22.12 #481

@LukasFritzeDev

Description

@LukasFritzeDev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions