jest: [Bug]: "Runner is not a constructor" when using nested relative path and Yarn
Version
30.0.3
Steps to reproduce
- Clone https://github.com/G-Rath/jest-runner-bug
- Run
yarn install cdintofoo/bar/dip- 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)
I’ll take a look soon later.
@G-Rath Forgot to mention that the latest
unrs-resolverv1.10.1 now supports this usage.@ljharb It’s not about
exportsfield,resolvefollows Node’s behavior here, I was saying resolvingjest-runner-../../..successfully viaresolveand Node itself could be a bug feature actually.As you see, none of the
dirscalculated isnode_modulesfolder in my last screenshot, it’s treatingjest-runner-../../..as..at thenode_modulesstep.@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:
node_modules/.binas well as when usingnpxjest-runner-eslintis actually running Jest, usingexecaI 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 😃