Vite plugin that transforms CommonJS modules to ESModules during development, enabling compatibility with Vite's native ESM dev server. As of v1.0.10, it supports static require, dynamic require, and exports conversion. It provides both a Vite plugin for transformation and an esbuild plugin for optimizeDeps. Key differentiator: specifically targets Vite dev mode, unlike general CJS-to-ESM tools. Release cadence is low. Requires Node >=14.18.0.
npm install vite-plugin-cjs2esmVerified import paths — ran on the pinned version, not inferred.
Configures Vite to convert CommonJS modules to ESM during development using the plugin and its esbuild counterpart.
Ensure production builds properly handle CJS dependencies via Vite's pre-bundling and rollup config.
Refactor synchronous code that uses dynamic require to handle asynchronous import() with .then() or await.
Check that the plugin works with your Vite version; consider using Vite's built-in pre-bundling or other plugins.
Use: import viteCjsToEsmPlugin from 'vite-plugin-cjs2esm'; then viteCjsToEsmPlugin.vitePlugin()
Run: npm install vite-plugin-cjs2esm --save-dev
Ensure dynamic paths are correctly formatted; test with explicit paths or adjust filter option.
No dependency data recorded yet.