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

fix(vite-node): don't fallback to cjs by default #924

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions docs/config/index.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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