Vitest "The requested module does not provide an export named X" in CI
Vitest resolved the module under native ESM, but the name you imported is not exported by it. This is usually a default-vs-named mix-up, or a CommonJS package whose named exports ESM cannot statically detect.
What this error means
A test fails at import with "SyntaxError: The requested module 'X' does not provide an export named 'Y'." It can pass under a bundler that does looser interop and fail under Vitest native ESM.
SyntaxError: The requested module 'lodash' does not provide an export named 'default'
❯ src/format.test.ts:1:8
1| import _ from 'lodash';
| ^Common causes
Named vs default import mismatch
The module exports a value under a different name (or only a default), so the specific named import does not exist.
CommonJS named exports are not statically analyzable
A CommonJS dependency does not expose named exports that ESM can detect, so import { x } from fails even though require would work.
How to fix it
Import the shape the module actually exports
- Check the package entry to see whether it is ESM or CommonJS and what it exports.
- Use a default or namespace import for CommonJS packages.
- Re-run so the import resolves.
// CommonJS package: use default/namespace import
import _ from 'lodash'; // ok
// or
import * as _ from 'lodash';Inline the dependency for interop
If a dependency ships only CommonJS, have Vitest process it so named exports resolve.
// vitest.config.ts
export default {
test: { server: { deps: { inline: ['problem-pkg'] } } },
};How to prevent it
- Match import style (default vs named) to what each package exports.
- Inline CommonJS-only dependencies that break ESM named imports.
- Test under Vitest locally so interop issues surface before CI.