Skip to content

Commit

Permalink
fix(vite-node): don't fallback to cjs by default (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 16, 2022
1 parent 7375347 commit d959f28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
20 changes: 16 additions & 4 deletions docs/config/index.md
Expand Up @@ -68,6 +68,22 @@ Externalize means that Vite will bypass the package to native Node. Externalized

Vite will process inlined modules. This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).

#### deps.fallbackCJS

- **Type** `boolean`
- **Default:** `false`

When a dependency is a valid ESM package, try to guess the cjs version based on the path.

This might potentially cause some misalignment if a package has different logic in ESM and CJS mode.

#### deps.interopDefault

- **Type:** `boolean`
- **Default:** `true`

Interpret CJS module's default as named exports.

### globals

- **Type:** `boolean`
Expand Down Expand Up @@ -223,10 +239,6 @@ Maximum number of threads

Minimum number of threads

### interopDefault

- **Type:** `boolean`

### testTimeout

- **Type:** `number`
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-node/src/externalize.ts
Expand Up @@ -72,7 +72,8 @@ async function _shouldExternalize(
return id

const isNodeModule = id.includes('/node_modules/')
id = isNodeModule ? guessCJSversion(id) || id : id
const guessCJS = isNodeModule && options?.fallbackCJS
id = guessCJS ? guessCJSversion(id) || id : id

if (matchExternalizePattern(id, defaultInline))
return false
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-node/src/types.ts
Expand Up @@ -3,7 +3,7 @@ export interface DepsHandlingOptions {
inline?: (string | RegExp)[]
/**
* Try to guess the CJS version of a package when it's invalid ESM
* @default true
* @default false
*/
fallbackCJS?: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/config.ts
Expand Up @@ -73,7 +73,7 @@ export interface InlineConfig {
* This will significantly improve the performance in huge repo, but might potentially
* cause some misalignment if a package have different logic in ESM and CJS mode.
*
* @default true
* @default false
*/
fallbackCJS?: boolean
}
Expand Down

0 comments on commit d959f28

Please sign in to comment.