Skip to content

Different Typescript treatment between vitest and vitest-browser #7395

@just-boris

Description

@just-boris

Describe the bug

This file runs successfully in standard vitest, but fails in vitest browser mode:

import { Something } from "./types";

export { Something };

export function getSomething(): Something {
  return {
    foo: 1,
    bar: "a",
  };
}

When running in browser mode, it prints this

 RUN  v3.0.4 /Users/serdiuk/coding/vitest-browser-typescript

 ❯  chromium  test/index.test.ts (0 test)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL   chromium  test/index.test.ts [ test/index.test.ts ]
SyntaxError: The requested module '/src/types.ts' does not provide an export named 'Something'
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  no tests
   Start at  23:28:11
   Duration  786ms (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 200ms)

Reproduction

Published a mini project here: https://github.com/just-boris/vitest-browser-typescript (not sure if browser mode can be used on StackBlitz)

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 164.55 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.2 - ~/n/bin/node
    npm: 10.8.2 - ~/n/bin/npm
    pnpm: 8.15.4 - ~/n/bin/pnpm
  Browsers:
    Chrome: 132.0.6834.160
    Safari: 18.2
  npmPackages:
    @vitest/browser: ^3.0.4 => 3.0.4
    playwright: ^1.50.1 => 1.50.1
    vitest: ^3.0.4 => 3.0.4

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