Skip to content

Vitest 4 can no longer have projects with import ... 'bun' #9257

@matthew-gladman-oua

Description

@matthew-gladman-oua

Describe the bug

When importing anything from bun, Vitest v4 throws an error:

src:

import { $ } from 'bun';

export async function example() {
  await $`echo hi`;
}

error:

Error: Failed to resolve entry for package "bun". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis

In Vitest v3, this code worked fine (I suspect because the calls to bun were mocked away), but in v4 it no longer works. Looking at the bun package.json it's a valid error... (there is no entry script). But I'm not sure if this check is useful here as we're never actually importing the file...

Mocking out the file that uses this import does not help, nor does mocking bun itself 😭

Reproduction

https://stackblitz.com/edit/vitejs-vite-j93mxww4?file=src%2Fenv.test.ts

System Info

System:
    OS: macOS 26.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 500.44 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.11.1 - /Users/matthew.gladman/.volta/tools/image/node/24.11.1/bin/node
    npm: 11.6.4 - /Users/matthew.gladman/.volta/tools/image/npm/11.6.4/bin/npm
    bun: 1.3.4 - /Users/matthew.gladman/projects/catalogue-verse/node_modules/.bin/bun
  Browsers:
    Chrome: 143.0.7499.41
    Edge: 143.0.3650.80
    Firefox: 145.0.1
    Safari: 26.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    Status

    P2 - 3

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions