Describe the bug
We have a package that has a browser ESM & Node CJS & ESM builds. So exports looks something like this:
"exports": {
"types": "./dist/node.d.ts",
"browser": "./dist/browser.mjs",
"import": "./dist/node.mjs",
"require": "./dist/node.js"
},
Vitest selects the Node ESM build even with environment: "jsdom". Annoyingly, this can be a good thing for some packages, and bad for others in tests.
See https://jestjs.io/docs/29.0/configuration#testenvironmentoptions-object for the config and special comment syntax for this issue supported by Jest.
This might be difficult to support without loader hooks though Node does have a --conditions flag.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-4jwegg?file=test/basic.test.ts
System Info
System:
OS: macOS 12.6.2
CPU: (10) arm64 Apple M1 Pro
Memory: 123.48 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.0/bin/yarn
npm: 9.2.0 - ~/.nvm/versions/node/v16.19.0/bin/npm
Browsers:
Chrome: 108.0.5359.124
Safari: 16.2
Used Package Manager
npm
Validations
Describe the bug
We have a package that has a browser ESM & Node CJS & ESM builds. So exports looks something like this:
Vitest selects the Node ESM build even with
environment: "jsdom". Annoyingly, this can be a good thing for some packages, and bad for others in tests.See https://jestjs.io/docs/29.0/configuration#testenvironmentoptions-object for the config and special comment syntax for this issue supported by Jest.
This might be difficult to support without loader hooks though Node does have a
--conditionsflag.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-4jwegg?file=test/basic.test.ts
System Info
System: OS: macOS 12.6.2 CPU: (10) arm64 Apple M1 Pro Memory: 123.48 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.0/bin/yarn npm: 9.2.0 - ~/.nvm/versions/node/v16.19.0/bin/npm Browsers: Chrome: 108.0.5359.124 Safari: 16.2Used Package Manager
npm
Validations