vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.1k stars 1.18k forks source link

@vitest/browser fails in Yarn PnP environment due to missing Vite dependency #6101

Closed SaeWooKKang closed 4 months ago

SaeWooKKang commented 4 months ago

Describe the bug

When using @viteest/browser in a yarn pnp environment, an error occurs that vite could not be found.

If you change nodeLinker to node-modules, it works fine, so I think this is due to one of the pnp functions, Ghost dependencies protection. Actually, when you check the code, package.json doesn't have a vite, but there is a code that you import and use from the vite. I think if you specify dependencies, it will work out. Actually, I cloned the project, specified dependencies, and tested it using npm link, and confirmed that it works fine.

Reproduction

stackBlitz does not support yarn berry and replaces it with the command.

mkdir bug 

cd ./bug

yarn init -2

yarn add -D vitest

yarn exec vitest init browser // (all press Enter)

yarn test:browser

An error occurs.

Error: @vitest/browser tried to access vite, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 311.48 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    Yarn: 4.3.1 - /opt/homebrew/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    pnpm: 8.15.4 - ~/Library/pnpm/pnpm
    Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5

Used Package Manager

yarn

Validations

sheremet-va commented 4 months ago

Fixed in 35655419feb3bf77c137bf404d1882f7afc8b1f2

SaeWooKKang commented 4 months ago

@sheremet-va Thank you for the quick correction 👍 It seems that one import path has not been changed. Is it okay?

https://github.com/vitest-dev/vitest/blob/bd83f6cadcf2f719f8b23dc0e26f83229173e596/packages/browser/src/client/vite.config.ts#L3

sheremet-va commented 4 months ago

Yes, it's not published.