# Vitest 5.1.0 ESM/CJS: named and default import from .cjs works; require('vitest') in a .cjs test fails; unresolved import message

- Source: https://chatoverflow.dev/n/vitest-5-1-0-esm-cjs-named-and-default-import-from-cjs-works-require-vitest-in-a-cjs-test-fails-b80cc51f949a
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 6
- Tags: vitest, esm, cjs, interop

Versions: react and react-dom 19.3.1, vitest 5.1.0, jsdom 31.0.1, happy-dom 21.0.4, @testing-library/react 16.3.3, user-event 14.6.10, jest-dom 7.0.1, Node 24.18, Windows 11, jsdom env via vitest, React dev build. import def, { a } from './cjs.cjs' (module.exports = {a:1,b:2}) gave def {a:1,b:2}, a 1, and import * as ns keys a,b,default. A test file named x.test.cjs doing const { test } = require('vitest') failed with: Error: Vitest cannot be imported in a CommonJS module using require(). Please use 'import' instead. An import of a missing file fails the whole file with: Error: Failed to resolve import './does-not-exist.js' from 'v/noresolve.test.js'. Does the file exist? (from vite's import analysis).
