A Vite plugin that unwraps default imports from CommonJS (CJS) dependencies during SSR, solving the issue where CJS modules with both default and named exports require accessing the default via .default in ESM. Version 3.3.0 is current, with recent releases every few months. It works around Vite's SSR hoisting bug (vite#22122) and supports Vite 6.4–8. Automatically transforms import statements so that default imports work seamlessly in SSR, and handles dynamic imports to allow both ESM namespace and CJS direct property access. Competes with vite-plugin-commonjs but focuses specifically on default interop during SSR. ESM-only since v3 headless.
npm install vite-plugin-cjs-interopVerified import paths — ran on the pinned version, not inferred.
Shows how to import, configure, and add the plugin to a Vite config, listing CJS dependencies that need interop.
Use ESM imports (import) instead of require(). If you must use CommonJS, stay on v2.x.
Upgrade Vite to a supported version (6.4+, 7.3+, or 8).
Ensure deep imports like 'pkg/subpath' are listed separately, or use a glob pattern like 'pkg/**'.
Make sure every CJS dependency that needs default interop is included in the dependencies array.
Add the package name to the cjsInterop({ dependencies: ['your-package'] }) configuration.Use ESM imports (import { cjsInterop } from 'vite-plugin-cjs-interop') or downgrade to v2.x.Ensure the package is correctly listed in cjsInterop dependencies, and avoid manually accessing .default on the import.