Registry / web-framework / vite-legacy-interop

vite-legacy-interop

JSON →
library1.0.4jsnpmunverified

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-interop
INSTALL
IMPORT
SIG · VITE-LEGACY-INTERO
V
vite-legacy-interop
web-frameworkjavascriptv1.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

legacyInterop
import { legacyInterop } from 'vite-legacy-interop'
import legacyInterop from 'vite-legacy-interop'
Default export is not available; use named import. ESM only.
LegacyInteropOptions
import type { LegacyInteropOptions } from 'vite-legacy-interop'
import { LegacyInteropOptions } from 'vite-legacy-interop'
Only for TypeScript type imports, not a runtime value.
LibConfig
import type { LibConfig } from 'vite-legacy-interop'
import { LibConfig } from 'vite-legacy-interop'
TypeScript only interface, not exported as value.

Configure vite-legacy-interop to wrap CJS subpath imports from 'legacy-lib' in ESM virtual modules.

// vite.config.ts import { defineConfig } from 'vite'; import { legacyInterop } from 'vite-legacy-interop'; export default defineConfig({ plugins: [ legacyInterop({ libs: ['legacy-lib'], showLog: true, apply: 'build', }), ], }); // Now imports like: // import Button from 'legacy-lib/lib/Button' // are transparently wrapped in ESM interop modules.
Debug
Known issues
breakingRequires Vite 8.x; incompatible with Vite 7 or earlier.
fix
Upgrade to Vite 8 or use alternative plugin for earlier Vite versions.
affects: >=1.0.0
gotchaPlugin must be placed before other plugins that transform imports.
fix
Ensure legacyInterop is first in the plugins array.
affects: >=1.0.0
deprecatedOption 'libDir' default is 'lib'; legacy packages with different directory must specify.
fix
Explicitly set 'libDir' if your package uses 'dist' or other paths.
affects: >=1.0.0
gotchaVirtual module IDs start with '\0legacy-interop:' which may conflict with other plugins.
fix
Avoid other plugins using the same namespace prefix.
affects: >=1.0.0
gotchaDoes not handle dynamic imports (import()) or require() calls; only static import statements.
fix
Use static imports for legacy CJS subpaths.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: The requested module 'legacy-lib/lib/Button' does not provide an export named 'default'
Rolldown does not perform CJS-to-ESM interop for subpath imports.
fix
Install and configure vite-legacy-interop with 'legacy-lib' in libs.
ReferenceError: require is not defined
Legacy CJS module is emitted as-is in ESM bundle.
fix
Add vite-legacy-interop plugin with the legacy library name.
Error: The plugin 'vite:legacy-interop' requires Vite >=8.0.0
Attempting to use with older Vite version.
fix
Upgrade Vite to 8.x or remove this plugin.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
viterequiredpeer dependency: requires Vite 8 (^8.0.0) to function
Agent activity
2 hits · last 30 days
node
2
Resources
vite-legacy-interop — npm install vite-legacy-interop · libregistry