Skip to content

Commit

Permalink
docs: improve interpretDefault docs (#2561)
Browse files Browse the repository at this point in the history
* docs: improve interpretDefault docs

* chore: cleanup

* Apply suggestions from code review

Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>

Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>
  • Loading branch information
sheremet-va and dammy001 committed Dec 23, 2022
1 parent ce5b4b8 commit a35ac70
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions docs/config/index.md
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

0 comments on commit a35ac70

Please sign in to comment.