Skip to content

fix: load vitest configs as ESM to fix broken test suite for older versions of node#502

Open
shanefontaine wants to merge 1 commit into
OpenRouterTeam:mainfrom
shanefontaine:fix/update-config-to-fix-test-suite
Open

fix: load vitest configs as ESM to fix broken test suite for older versions of node#502
shanefontaine wants to merge 1 commit into
OpenRouterTeam:mainfrom
shanefontaine:fix/update-config-to-fix-test-suite

Conversation

@shanefontaine

Copy link
Copy Markdown

Summary

The test suite only works on node versions ^20.19.0 || >=22.12.0. The Vitest configs import ESM-only tooling (notably vite-tsconfig-paths), but CJS can't require() an ESM-only module on node versions below that range. Support for loading native ESM via require() landed in node@22.12.0 and was backported to node@20.19.0.

This PR fixes test compatibility for older versions of node and removes any ambiguity about the expected module type, following the official recommended usage by both vite and vite-tsconfig-paths.

Root Cause

The build system of this repo gracefully handles CJS and ESM only within the src dir (via tsup). However, the test configs are handled out-of-band by vitest(which uses vite). With .ts and no type:module, vite loads the bundled config via require(), which breaks with ESM only deps vite-tsconfig-paths. Using .mts forces the ESM path.

Where I Observed This

Locally running tests against this repo with any node version below ^20.19.0 || >=22.12.0.

To reproduce:

> nvm use 20.18.3
> pnpm test:e2e

Fix

Update the relevant vitest files and configs to explicitly signal that these these files should be treated as ESM. This removes any remaining module choice ambiguity in the repo and fixes the broken test suite on older node versions.

Test plan

  •  Confirmed the existing test suite fails to run on main with node versions 20.18.3 and 22.11.0. Confirmed that it succeeds on main with node versions 20.19.0, 22.12.0, and 24.10.0.
  •  Confirmed the test suite works with all modern versions of node.
  •  Full pnpm test:node suite passes.
  •  pnpm typecheck clean.
  •  pnpm stylecheck (biome) clean.
  •  Added an empty changeset.

Suggested review order

  1. vitest.*.config.mts — updated the file type to explicitly signal ESM.
  2. package.json — updated test scripts to reflect new file type change.
  3. tsconfig.json — updated include property with the new file types. This allows the tsc build tool to catch type issues (when running pnpm typecheck).

Notes

  • Build systems are very opinionated, diverse, and sensitive. This PR attempts to resolve the underlying issue (broken test suite) with the most minimally invasive solution possible, while attempting to adhere to what I believe aligns with culture and spirit of the existing repo and team. If this fix adds more confusion than it is worth, then it should absolutely not be merged.
    • A reasonable alternative solution would be to just modify package.json to { "engines": { "node": "^20.19.0 || >=22.12.0" } }
  • If a moduleResolution besides bundler is desired for i.e. stricter build controls, then this fix would need to be implemented in another way. However, a change of that nature would require a number of updates to the build tooling that would certainly handle this in stride.
  • I did not file an issue first but will be happy to do so if preferred.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant