Skip to content

fetch is undefined with experimentalVmThreads: true #4199

@nstepien

Description

@nstepien

Describe the bug

Without experimentalVmThreads, our JSDOM tests can use Node's fetch implementation in our tests.
When experimentalVmThreads is enabled, the global fetch is missing.

Reproduction

vite.config.js:

import { defineConfig } from 'vite';

export default defineConfig({
  test: {
    experimentalVmThreads: true,
    environment: 'jsdom'
  }
});

test file:

import { test, expect } from 'vitest';

test('global fetch', () => {
  expect(globalThis.fetch).toBeDefined();
});

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
    Memory: 23.16 GB / 31.88 GB
  Binaries:
    Node: 20.8.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (117.0.2045.43)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitejs/plugin-react: ^4.1.0 => 4.1.0
    @vitest/coverage-v8: ^0.34.5 => 0.34.5
    vite: ^4.4.9 => 4.4.9
    vitest: ^0.34.5 => 0.34.5

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions