Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/guide/common-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,51 @@ vitest --pool=forks
```
:::

## Custom package conditions are not resolved

If you are using custom conditions in your `package.json` [exports](https://nodejs.org/api/packages.html#package-entry-points) or [subpath imports](https://nodejs.org/api/packages.html#subpath-imports), you may find that Vitest does not respect these conditions by default.

For example, if you have the following in your `package.json`:

```json
{
"exports": {
".": {
"custom": "./lib/custom.js",
"import": "./lib/index.js"
}
},
"imports": {
"#internal": {
"custom": "./src/internal.js",
"default": "./lib/internal.js"
}
}
}
```

By default, Vitest will only use the `import` and `default` conditions. To make Vitest respect custom conditions, you need to configure [`ssr.resolve.conditions`](https://vite.dev/config/ssr-options#ssr-resolve-conditions) in your Vitest config:

```ts [vitest.config.js]
import { defineConfig } from 'vitest/config'

export default defineConfig({
ssr: {
resolve: {
conditions: ['custom', 'import', 'default'],
},
},
})
```

::: tip Why `ssr.resolve.conditions` and not `resolve.conditions`?
Vitest inherits Vite's configuration convention where:
- [`resolve.conditions`](https://vite.dev/config/shared-options#resolve-conditions) is used for browser-like environments (jsdom, happy-dom, or custom environments with `transformMode: 'web'`)
- [`ssr.resolve.conditions`](https://vite.dev/config/ssr-options#ssr-resolve-conditions) is used for Node-like environments (node, or custom environments with `transformMode: 'ssr'`)

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

## Segfaults and native code errors

Running [native NodeJS modules](https://nodejs.org/api/addons.html) in `pool: 'threads'` can run into cryptic errors coming from the native code.
Expand Down