test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

Test fails to run when dependencies with CommonJS module import.

Open hanool opened this issue 4 weeks ago • 0 comments

Environment

Operating system Linux 6.6.87.2-microsoft-standard-WSL2
CPU 12th Gen Intel(R) Core(TM) i7-1255U (12 cores) Node.js version v24.11.1
nuxt/cli version 3.31.3
Package manager npm 11.6.2
Nuxt version 4.2.2
Nitro version 2.12.9
Builder vite 7.3.0
Config compatibilityDate, devtools, modules, plugins Modules @nuxt/eslint 1.12.1, @nuxt/test-utils 3.21.0

Reproduction

repro

  1. create fresh nuxt app with npm create nuxt@latest
  2. npm i --save-dev @nuxt/test-utils vitest @vue/test-utils happy-dom to creat test.
  3. add dependencies which has cjs module import(for me it was @mescius/activereportsjs-vue)
  4. create plugin with 3.
  5. run npx vitest

Describe the bug

When there is cjs module import in dependencies, npx vitest fails with plugin load. Tried with deps.interopDefault: false in vitest config but not fixed.

Additional context

No response

Logs

> npx vitest
FAIL   nuxt  ../test/nuxt/foo.test.ts [ test/nuxt/foo.test.ts ]
SyntaxError: Named export 'PaletteColorUtility' not found. The requested module '../../@dt/dvchart.cjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '../../@dt/dvchart.cjs';
const { PaletteColorUtility: EQe, FlexDV: MQe } = pkg;

 ❯ plugins/ar-vue.ts:1:1
      1| import { Viewer } from "@mescius/activereportsjs-vue";
       | ^
      2|
      3| export default defineNuxtPlugin(() => {

hanool avatar Dec 18 '25 05:12 hanool