jest: [Bug]: "Runner is not a constructor" when using nested relative path and Yarn

Version

30.0.3

Steps to reproduce

  1. Clone https://github.com/G-Rath/jest-runner-bug
  2. Run yarn install
  3. cd into foo/bar/dip
  4. Run npx jest

Alternatively, see the CI: https://github.com/G-Rath/jest-runner-bug/blob/main/.github/workflows/ci.yml & https://github.com/G-Rath/jest-runner-bug/actions/runs/15981985791/job/45078225921

Expected behavior

Jest to be happy

Actual behavior

Jest errors about “Runner is not a constructor”

Additional context

This was found via https://github.com/jest-community/jest-runner-eslint/pull/291 where I’ve already done some digging, and spoken to @JounQin about - originally we were not sure if this is actually something Jest officially supports, but now that I know it only seems to happen on Yarn and when nested more than two directories I think it’s clearly a bug.

The issue seems to lie with jest-resolve and/or unrs-resolver - see this comment for the work I’ve done so far

Environment

System:
    OS: Linux 6.6 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
  Binaries:
    Node: 20.19.0 - ~/.nodenv/versions/20.19.0/bin/node
    Yarn: 1.22.22 - ~/.nodenv/versions/20.19.0/bin/yarn
    npm: 10.8.2 - ~/.nodenv/versions/20.19.0/bin/npm

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

I’ll take a look soon later.

@G-Rath Forgot to mention that the latest unrs-resolver v1.10.1 now supports this usage.

If that package has exports, then you’re just trolling, because resolve doesn’t support that yet, as you well know. I’m talking about require.resolve

@ljharb It’s not about exports field, resolve follows Node’s behavior here, I was saying resolving jest-runner-../../.. successfully via resolve and Node itself could be a bug feature actually.

As you see, none of the dirs calculated is node_modules folder in my last screenshot, it’s treating jest-runner-../../.. as .. at the node_modules step.

@ljharb Do you think resolving jest-runner-../../../ successfully is following Node spec or just a undefined behavior?

@JounQin I’ll defer to @SimenB on the final decision about if this is going to be classed not a bug in Jest, but a few points:

I agree with Jordan, fwiw (as in - this is a bug that should be fixed, not worked around downstream)

Technically I don’t think it’s a blocker but it’d be nice to not have to work around this bug forever 😃