Open wparsons-heins-globality opened 2 days ago
When importing a CJS module I'm finding that I'm getting different results in vitest when compared with node and tsx.
For instance:
import pkg from 'some-cjs-package'; // node / tsx // pkg = { default: { defaultExportedFunction } } // vitest // pkg = { defaultExportedFunction }
Here's a minimized version of the CJS file I'm importing:
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var specs = {}; exports.default = specs;
https://stackblitz.com/edit/vitest-dev-vitest-qox16t?file=test%2Fbasic.test.ts
System: OS: macOS 14.5 CPU: (11) arm64 Apple M3 Pro Memory: 1.25 GB / 18.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.16.0 - ~/.local/state/fnm_multishells/36412_1728045710155/bin/node Yarn: 1.22.22 - ~/.local/state/fnm_multishells/36412_1728045710155/bin/yarn npm: 10.8.1 - ~/.local/state/fnm_multishells/36412_1728045710155/bin/npm Browsers: Brave Browser: 129.1.70.123 Chrome: 129.0.6668.90 Safari: 17.5 npmPackages: vitest: ^2.0.5 => 2.0.5
yarn
This is by design. You can disable this with deps.interopDefault option.
deps.interopDefault
Describe the bug
When importing a CJS module I'm finding that I'm getting different results in vitest when compared with node and tsx.
For instance:
Here's a minimized version of the CJS file I'm importing:
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-qox16t?file=test%2Fbasic.test.ts
System Info
Used Package Manager
yarn
Validations