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

docs: improve interpretDefault docs #2561

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ Files to exclude from the test run, using glob pattern.

### deps

- **Type:** `{ external?, inline? }`
- **Type:** `{ external?, inline?, ... }`

Handling for dependencies inlining or externalizing
Handling for dependencies resolution.

#### deps.external

Expand Down Expand Up @@ -121,16 +121,32 @@ This might potentially cause some misalignment if a package has different logic
- **Type:** `boolean`
- **Default:** `false`

Use [experimental Node loader](https://nodejs.org/api/esm.html#loaders) to resolve imports inside `node_modules`, using Vite resolve algorithm.
Use [experimental Node loader](https://nodejs.org/api/esm.html#loaders) to resolve imports inside externalized files, using Vite resolve algorithm.

If disabled, your `alias` and `<plugin>.resolveId` won't affect imports inside `node_modules` or `deps.external`.
If disabled, your `alias` and `<plugin>.resolveId` won't affect imports inside externalized packages (by default, `node_modules`).

#### deps.interopDefault

- **Type:** `boolean`
- **Default:** `true`
- **Default:** `false` if `environment` is `node`, `true` otherwise

Interpret CJS module's default as named exports. Some dependencies only bundle CJS modules and don't use named exports that Node.js can statically analyze when a package is imported using `import` syntax instead of `require`. When importing such dependencies in Node environment using named exports, you will see this error:

```
import { read } from 'fs-jetpack';
^^^^
SyntaxError: Named export 'read' not found. The requested module 'fs-jetpack' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export.
```

Vitest doesn't do static analysis, and cannot fail before your running code, so you will most likely see this error when running tests:

```
TypeError: createAsyncThunk is not a function
TypeError: default is not a function
```

Interpret CJS module's default as named exports.
If you are using bundlers or transpilers that bypass this Node.js limitation, you can enable this option manually. By default, Vitest assumes you are using Node ESM syntax, when `environment` is `node`, and doesn't interpret named exports.

### benchmark

Expand Down