Skip to content

Dependency optimization does not work in SSR transform mode #4910

@kherock

Description

@kherock

Describe the bug

Vite lazily initializes the SSR deps optimizer when ViteDevServer.ssrLoadModule is called for the first time.

Vitest/vite-node does not seem to ever call this method, so the optimizer never ends up being initialized into the devSsrDepsOptimizerMap, which Vite uses to resolve the appropriate optimizer.

Reproduction

I'm currently running Vitest 0.34 with Vite 4, but I was able to recreate the issue with the latest Vitest and Vite 5:
https://stackblitz.com/edit/vitest-dev-vitest-1flfpv?file=test%2Fweb.test.ts

System Info

System:
    OS: macOS 13.6.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 103.50 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.3 - /opt/homebrew/bin/npm
    pnpm: 7.9.5 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.199
    Edge: 120.0.2210.121
    Safari: 17.2.1
  npmPackages:
    @vitest/coverage-v8: ^0.34.6 => 0.34.6 
    vitest: ^0.34.6 => 0.34.6

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