{"id":22571,"library":"vite-legacy-interop","title":"vite-legacy-interop","description":"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.","status":"active","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/ElJijuna/vite-legacy-interop","tags":["javascript","vite","plugin","legacy","interop","typescript"],"install":[{"cmd":"npm install vite-legacy-interop","lang":"bash","label":"npm"},{"cmd":"yarn add vite-legacy-interop","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-legacy-interop","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: requires Vite 8 (^8.0.0) to function","package":"vite","optional":false}],"imports":[{"note":"Default export is not available; use named import. ESM only.","wrong":"import legacyInterop from 'vite-legacy-interop'","symbol":"legacyInterop","correct":"import { legacyInterop } from 'vite-legacy-interop'"},{"note":"Only for TypeScript type imports, not a runtime value.","wrong":"import { LegacyInteropOptions } from 'vite-legacy-interop'","symbol":"LegacyInteropOptions","correct":"import type { LegacyInteropOptions } from 'vite-legacy-interop'"},{"note":"TypeScript only interface, not exported as value.","wrong":"import { LibConfig } from 'vite-legacy-interop'","symbol":"LibConfig","correct":"import type { LibConfig } from 'vite-legacy-interop'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { legacyInterop } from 'vite-legacy-interop';\n\nexport default defineConfig({\n  plugins: [\n    legacyInterop({\n      libs: ['legacy-lib'],\n      showLog: true,\n      apply: 'build',\n    }),\n  ],\n});\n\n// Now imports like:\n// import Button from 'legacy-lib/lib/Button'\n// are transparently wrapped in ESM interop modules.","lang":"typescript","description":"Configure vite-legacy-interop to wrap CJS subpath imports from 'legacy-lib' in ESM virtual modules."},"warnings":[{"fix":"Upgrade to Vite 8 or use alternative plugin for earlier Vite versions.","message":"Requires Vite 8.x; incompatible with Vite 7 or earlier.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure legacyInterop is first in the plugins array.","message":"Plugin must be placed before other plugins that transform imports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly set 'libDir' if your package uses 'dist' or other paths.","message":"Option 'libDir' default is 'lib'; legacy packages with different directory must specify.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Avoid other plugins using the same namespace prefix.","message":"Virtual module IDs start with '\\0legacy-interop:' which may conflict with other plugins.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use static imports for legacy CJS subpaths.","message":"Does not handle dynamic imports (import()) or require() calls; only static import statements.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install and configure vite-legacy-interop with 'legacy-lib' in libs.","cause":"Rolldown does not perform CJS-to-ESM interop for subpath imports.","error":"SyntaxError: The requested module 'legacy-lib/lib/Button' does not provide an export named 'default'"},{"fix":"Add vite-legacy-interop plugin with the legacy library name.","cause":"Legacy CJS module is emitted as-is in ESM bundle.","error":"ReferenceError: require is not defined"},{"fix":"Upgrade Vite to 8.x or remove this plugin.","cause":"Attempting to use with older Vite version.","error":"Error: The plugin 'vite:legacy-interop' requires Vite >=8.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}