Skip to content

[Bug]: Preset modules defining path to jest-preset.js via exports are not working on Windows #15511

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

Open
Filipoliko opened this issue Feb 17, 2025 · 5 comments

Comments

@Filipoliko
Copy link

Version

29.7.0

Steps to reproduce

  1. Start your favorite Windows machine, this bug is only reproducible there :)
  2. Clone https://github.com/Filipoliko/jest-preset-windows
  3. Run npm ci
  4. Run npm test
  5. You should see the error

Expected behavior

No error, Jest should recognise that package.json file of my-jest-preset defines exports for ./jest-preset.

Actual behavior

Jest fails to start the test run due to missing jest-preset.js file, but only on Windows machines.

Jest v29.7.0 error message:

> github-jest-preset-windows@1.0.0 test
> jest
● Validation Error:
  Preset my-jest-preset not found.
  Configuration Documentation:
  https://jestjs.io/docs/configuration
Error: Process completed with exit code 1.

Jest v30.0.0-alpha.7 error message:

> github-jest-preset-windows@1.0.0 test
> jest
● Validation Error:
  Preset my-jest-preset not found relative to rootDir D:\a\jest-preset-windows\jest-preset-windows.
  Configuration Documentation:
  https://jestjs.io/docs/configuration
Error: Process completed with exit code 1.

Additional context

See pipeline results https://github.com/Filipoliko/jest-preset-windows/actions/runs/13372503574 (v29), https://github.com/Filipoliko/jest-preset-windows/actions/runs/13372781509 (v30) - it shows that the same jest configuration works for Linux and MacOS, but fails for Windows.

The path to jest-preset.js file is defined via exports definition in package.json - see https://github.com/Filipoliko/jest-preset-windows/blob/main/packages/my-jest-preset/package.json#L6

Environment

System:
    OS: Windows 10 10.0.20348
    CPU: (4) x64 AMD EPYC 7763 64-Core Processor                
  Binaries:
    Node: 22.13.1 - C:\hostedtoolcache\windows\node\22.13.1\x64\node.EXE
    Yarn: 1.22.22 - C:\npm\prefix\yarn.CMD
    npm: 10.9.2 - C:\hostedtoolcache\windows\node\22.13.1\x64\npm.CMD
  npmPackages:
    jest: 30.0.0-alpha.7 => 30.0.0-alpha.7
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 19, 2025
@Filipoliko
Copy link
Author

Bump

@github-actions github-actions bot removed the Stale label Mar 19, 2025
@jagiles-ren
Copy link

We ran into the same issue today. We have a mix of machine types across our development team and didn't notice the issue until we started rolling our presets out for broader use. Any fix or workaround would be greatly appreciated.

@Filipoliko
Copy link
Author

@jagiles-ren as a workaround, we added jest-preset.js file to the root of our npm package which gets picked up by windows machines. It just re-exports the preset file (and makes the exports definition pretty much useless 😅)

See https://github.com/seznam/ima/blob/master/packages/testing-library/jest-preset.js for example

@jagiles-ren
Copy link

@Filipoliko - yeah we discovered the same thing. Jest on Windows appears to be ignoring exports and combining paths to resolve the reference to the preset file. We have a library that exports a number of different configuration objects and so we had the preset at a subdirectory within the lib/ directory. We noticed on windows if we added lib/ to our configured preset it worked (obviously ignoring the exports from the package.json).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants