Make the experimental node loader handle CJS to ESM conversion

Open
#2,740 2 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript, vite

Research direction

No files, tests, or specific entry points are named. Start by locating Vitest's experimental node loader and its dependency inlining path, then compare the intended CJS-to-ESM handling with the tsx approach mentioned. Done means affected packages such as lodash work without inlining the entire transitive dependency chain.

Written by the indexing model from the issue text.

Description

discussion enhancement p2-nice-to-have
Clear and concise description of the problem

Some packages export CJS entry points that have bad named exports for the ESM named exports heuristic employed by node. Those work with plain Vite but fail with vitest. (e.g. lodash)

To support them you currently need to deps.inline them, which also requires inlining any module that transitively imports such problem modules.

Suggested solution

The experimental node loader can handle such conversion without requiring to inline the entire dependency chain. Similar to how tsx works.

Alternative

Keep inlining the entirety of such dependency chains, or don't use such named imports from problem packages.

Additional context

No response

Validations
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 21h
Merged PRs (30d)
92

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vitest-dev/vitest

All issues in vitest-dev/vitest

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.