A Vite 8 plugin that wraps legacy CJS subpath imports in ESM-compatible virtual modules to prevent runtime interop errors. Current version 1.0.4, actively maintained. Designed for Vite 8 and Rolldown, it intercepts imports like `legacy-lib/lib/Button` and replaces them with virtual ESM wrappers that handle CJS-to-ESM interop, solving `SyntaxError` and `ReferenceError` at runtime. Differentiators: targeted at Vite 8 with Rolldown, supports multiple libraries and nested subpaths, minimal configuration, includes debug logging.
npm install vite-legacy-interopVerified import paths — ran on the pinned version, not inferred.
Configure vite-legacy-interop to wrap CJS subpath imports from 'legacy-lib' in ESM virtual modules.
Upgrade to Vite 8 or use alternative plugin for earlier Vite versions.
Ensure legacyInterop is first in the plugins array.
Explicitly set 'libDir' if your package uses 'dist' or other paths.
Avoid other plugins using the same namespace prefix.
Use static imports for legacy CJS subpaths.
Install and configure vite-legacy-interop with 'legacy-lib' in libs.
Add vite-legacy-interop plugin with the legacy library name.
Upgrade Vite to 8.x or remove this plugin.