Skip to content

[Vitest 3] "Intl.Collator is not a constructor" when using fake timers #7142

@spaceemotion

Description

@spaceemotion

Describe the bug

I am trying to upgrade to the latest Vitest 3 Beta. Our project does not use Vite for the build-pipeline (only a simple esbuild config, in fact), and we didn't need to do anything so far to get our tests running (we don't even have a vitest config).

However, after the upgrade, we suddenly see the following error in the console:

Intl.Collator is not a constructor

TypeError: Intl.Collator is not a constructor
 ❯ src/services/xxxxx.ts:96:24
     94| };
     95|
     96| const nameComparator = new Intl.Collator('en', {
       |                        ^
     97|   sensitivity: 'base',
     98|   numeric: true,

I thought it might have to do with the Vite 6 module resolution changes, but even tinkering with that one broke more than i liked. The project runs on Node v22, and Vitest v2 has worked without an issue so far.

The error also happens when I run vitest in isolation mode.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-ptkpew1o?file=test%2Fbasic.test.ts

Once the async import gets resolved, Vitest doesn't know what Intl. is.

System Info

System:
  OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
  CPU: (16) x64 AMD Ryzen 9 7950X 16-Core Processor
  Memory: 25.82 GB / 35.24 GB
  Container: Yes
  Shell: 3.6.1 - /usr/bin/fish
Binaries:
  Node: 22.2.0 - /mnt/wslg/runtime-dir/fnm_multishells/40485_1735384937185/bin/node
  npm: 10.7.0 - /mnt/wslg/runtime-dir/fnm_multishells/40485_1735384937185/bin/npm
  pnpm: 8.15.5 - /mnt/wslg/runtime-dir/fnm_multishells/40485_1735384937185/bin/pnpm
  bun: 1.1.8 - ~/.bun/bin/bun
npmPackages:
  vitest: 3.0.0-beta.3 => 3.0.0-beta.3

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions