Registry /
testing / react-cosmos-plugin-vite
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
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
reactCosmosVitePlugin
✓ import { reactCosmosVitePlugin } from 'react-cosmos-plugin-vite'
✗ import reactCosmosVitePlugin from 'react-cosmos-plugin-vite'
The plugin is a named export, not a default export. Use braces.
generateCosmosIndexHtml
✓ import { generateCosmosIndexHtml } from 'react-cosmos-plugin-vite'
✗ const generateCosmosIndexHtml = require('react-cosmos-plugin-vite').generateCosmosIndexHtml
The package is ESM-only; require() is not supported.
defineConfig (from vite)
✓ import { defineConfig } from 'vite'; import { reactCosmosVitePlugin } from 'react-cosmos-plugin-vite'; export default defineConfig({ plugins: [reactCosmosVitePlugin()] })
✗ module.exports = { plugins: [require('react-cosmos-plugin-vite').reactCosmosVitePlugin()] }
Vite config must be ESM in most setups; avoid CommonJS module.exports.
Shows how to configure Vite with the React Cosmos plugin, install peer dependencies, and start the Cosmos dev server.
// vite.config.ts
import { defineConfig } from 'vite';
import { reactCosmosVitePlugin } from 'react-cosmos-plugin-vite';
export default defineConfig({
plugins: [reactCosmosVitePlugin()],
});
// Install peer dependencies:
// npm install --save-dev react-cosmos react-cosmos-plugin-vite vite react react-dom
// Run Cosmos:
// npx cosmos
Errors
Common errors & fixes
Error: Cannot find module 'react-cosmos-plugin-vite'
The package is not installed or not in node_modules.
fixRun npm install --save-dev react-cosmos-plugin-vite.
TypeError: reactCosmosVitePlugin is not a function
Incorrect import (default import instead of named import) or using require() in ESM context.
fixUse `import { reactCosmosVitePlugin } from 'react-cosmos-plugin-vite'`. Error: The plugin requires at least Vite 4.0.0
Outdated Vite version.
fixUpgrade Vite to version 4+ with `npm install vite@latest`.
Error: 'react' must be version >=18.0.0
React version too old for v7 plugin.
fixUpgrade React to 18 or later, or downgrade plugin to v6 (which supports React 17).
Audit
Dependencies
viterequiredRequired to run the Vite dev server and build pipeline
react-cosmosrequiredCore library for component isolation and fixture management
reactrequiredPeer dependency for React rendering
react-domrequiredPeer dependency for DOM rendering