Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies that have export conditions for node and the browser are resolving to node even when running tests in JSDOM #4757

Closed
6 tasks done
tylerbmyers opened this issue Dec 15, 2023 · 1 comment

Comments

@tylerbmyers
Copy link

Describe the bug

Dependencies that have export conditions for node and the browser are resolving to node even when running tests in JSDOM. This can cause the packages to not behave as intended running the browser code in the JSDOM environment instead of the node code targeting SSR use cases.

Reproduction

This is related to this issue. Here is a repo that demonstrates the issue.

System Info

System:
    OS: macOS 13.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.45 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.12.1 - ~/.nvm/versions/node/v18.16.0/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.2
  npmPackages:
    @vitejs/plugin-react: ^4.2.0 => 4.2.1 
    vite: ^5.0.0 => 5.0.7 
    vitest: ^1.0.4 => 1.0.4

Used Package Manager

yarn

Validations

@sheremet-va
Copy link
Member

This is intentional. The ecosystem doesn't have a consensus on how exports conditions are used. Vitest follows the idea that it should only apply if output code is executed in the browser. Even though JSDOM emulates browser globals, it doesn't change how imports are working.

But you can always manually add any condition to resolve.conditions field:

export default defineConfig({
  resolve: {
    conditions: ['browser']
  },
})

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants