4

I'm trying to migrate to vitest and facing a problem. One of the tests failed because it is reading a CommonJS file from one of the dependencies. The run does not fail on other tests that not using imports from CommonJS files

This is what my defineConfig in vitest.config.ts looks like:

import graphql from '@rollup/plugin-graphql';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [
    graphql(),
    react()
  ],
  test: {
    environment: 'jsdom',
    deps: {
      registerNodeLoader: true,
      fallbackCJS: true,
    },
  },
});

This is the error I got:

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' 
file extension and '/Users/nadavnassi/Desktop/dev/admin-client/node_modules/@rapidapi/ui-lib-icons/package.json' 
contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
TripleN
  • 41
  • 3

0 Answers0