Skip to content

can't run unit tests with jest when using esm modules, typescript and undici v5.16.0 #1878

@marinrusu1997

Description

@marinrusu1997

Bug Description

When trying to run unit tests with jest for files which use undici an error is thrown.

Reproducible By

You can reproduce this error by cloning this repo. README contains steps to reproduce the bug.

Expected Behavior

Unit tests should complete successfully.

Logs & Screenshots

This is the error shown by jest:

 Must use import to load ES Module: /Users/marin/Development/jest-undici-esm-bug/node_modules/undici/lib/llhttp/llhttp.wasm

      at Runtime.requireModule (node_modules/jest-runtime/build/index.js:817:21)
          at async Promise.all (index 0)
          at async Promise.all (index 0)

Also notice that if you lower the undici version, let's say to v5.15.0, a different issue will be thrown

/Users/marin/Development/jest-undici-esm-bug/node_modules/undici/lib/client.js:1184
        if (socket[kParser].timeoutType !== TIMEOUT_IDLE) {
                            ^

TypeError: Cannot read properties of undefined (reading 'timeoutType')
    at _resume (/Users/marin/Development/jest-undici-esm-bug/node_modules/undici/lib/client.js:1184:29)
    at resume (/Users/marin/Development/jest-undici-esm-bug/node_modules/undici/lib/client.js:1148:3)
    at connect (/Users/marin/Development/jest-undici-esm-bug/node_modules/undici/lib/client.js:1133:3)

Environment

MacOS Monterey
Node v16.14.2
Undici v5.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions