Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Related

Users cannot resolve package exports or subpath imports with custom conditions in Vitest because ssr.resolve.conditions configuration is undocumented, leading to confusion about why resolve.conditions doesn't work.

Changes

  • Added "Custom package conditions are not resolved" section to docs/guide/common-errors.md
  • Documented the solution using ssr.resolve.conditions configuration
  • Explained Vite's convention: resolve.conditions for browser-like environments (jsdom, happy-dom, or custom environments with transformMode: 'web'), and ssr.resolve.conditions for Node-like environments (node, or custom environments with transformMode: 'ssr')
  • Included examples for both package exports and subpath imports
  • Included runtime-conditional example (Bun vs Node)

Example

// vitest.config.js
export default defineConfig({
  ssr: {
    resolve: {
      conditions: ['custom', 'import', 'default'],
    },
  },
})

This works for both package exports and subpath imports. By default, Vitest uses the node environment which has transformMode: 'ssr', so it uses ssr.resolve.conditions for module resolution.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Jan 5, 2026

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 707ba3b
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/695b7d69bc24630008580e5b
😎 Deploy Preview https://deploy-preview-9392--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Propose documentation changes for issue 9391 docs: document ssr.resolve.conditions for subpath imports with custom conditions Jan 5, 2026
Copilot AI requested a review from hi-ogawa January 5, 2026 09:01
::: tip Why `ssr.resolve.conditions` and not `resolve.conditions`?
Vitest inherits Vite's configuration convention where:
- `resolve.conditions` is used for client-side application code (browser environments)
- `ssr.resolve.conditions` is used for server-side application code (Node.js environments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, transform mode is based on the environment (jsdom/happy-dom use resolve.conditions), custom environments can define transformMode property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b21497b - clarified that transform mode is based on the environment (jsdom/happy-dom use resolve.conditions, node uses ssr.resolve.conditions), and custom environments can define transformMode property.

@hi-ogawa hi-ogawa changed the title docs: document ssr.resolve.conditions for subpath imports with custom conditions docs: document ssr.resolve.conditions for custom conditions Jan 7, 2026
```
:::

## Subpath imports with custom conditions are not resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This is not only for sub path imports but any package condition in general. See #8764. Rewrite section with the framing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten in b21497b - changed section title to "Custom package conditions are not resolved" and expanded examples to include both package exports and subpath imports, addressing issue #8764.

@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 1674975
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/695e0d1bcf78e90008bb10b0
😎 Deploy Preview https://deploy-preview-9392--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title docs: document ssr.resolve.conditions for custom conditions docs: document ssr.resolve.conditions for custom package conditions Jan 7, 2026
Copilot AI requested a review from hi-ogawa January 7, 2026 03:30
@hi-ogawa hi-ogawa marked this pull request as ready for review January 7, 2026 04:36
- Clarify Vite environment configuration convention
- Fix viteEnvironment value from 'web' to 'client'
- Add reference to environment config documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@sheremet-va sheremet-va merged commit 41d8276 into main Jan 8, 2026
10 checks passed
@sheremet-va sheremet-va deleted the copilot/propose-doc-change-issue-9391 branch January 8, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants