-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Describe the bug
If we have a package subpath imports defined with custom conditions, vitest always runs resolve to import and default condition.
Say we have sub path import with conditions. If we run the scripts in general with bun, nodejs etc the import conditions are respected.
"imports": {
"#my-lib": {
"bun": "./lib/bun_lib.js",
"import": "./lib/node_lib.js"
}
},But when we run tests on a file which is using that import it does always use import condition.
And that is not related to the Bun or any other runtime. Any condition under subpath imports are not processed by when imported inside the tests for the Vitest.
Tried to add resolve config, but that also does not work.
resolve: {
conditions: ['bun', 'import', 'default']
}Reproduction
Full code is given at:
https://github.com/nazarhussain/vitest-subpath-import-conditions
And we run with NodeJS
npx vitest run
RUN v4.0.8 /Users/nazar/Hub/Lodestar/dev/vitest-import-alias
stdout | test/index.test.js > test > add
sum from node
✓ test/index.test.js (1 test) 1ms
✓ test (1)
✓ add 1ms
Test Files 1 passed (1)
Tests 1 passed (1)
And if we run with Bun.
bun x --bun vitest run
RUN v4.0.8 /Users/nazar/Hub/Lodestar/dev/vitest-import-alias
stdout | test/index.test.js > test > add
sum from node
✓ test/index.test.js (1 test) 3ms
✓ test (1)
✓ add 2ms
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 09:42:28
System Info
System:
OS: macOS 26.1
CPU: (11) arm64 Apple M3 Pro
Memory: 142.50 MB / 18.00 GB
Shell: 5.9 - /opt/homebrew/bin/zsh
Binaries:
Node: 22.13.0 - /Users/nazar/.asdf/installs/nodejs/22.13.0/bin/node
Yarn: 1.22.22 - /Users/nazar/.asdf/installs/nodejs/22.13.0/bin/yarn
npm: 10.9.2 - /Users/nazar/.asdf/plugins/nodejs/shims/npm
pnpm: 10.13.1 - /Users/nazar/.bun/bin/pnpm
bun: 1.3.1 - /Users/nazar/.asdf/shims/bun
Deno: 2.2.8 - /Users/nazar/.asdf/shims/deno
Browsers:
Brave Browser: 142.1.84.135
Edge: 140.0.3485.54
Safari: 26.1
npmPackages:
vitest: ^4.0.8 => 4.0.8Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.