Registry / testing / react-cosmos-plugin-vite

react-cosmos-plugin-vite

JSON →
library7.3.0jsnpmunverified

Official Vite plugin for React Cosmos, a development tool for building and testing React components in isolation. Version 7.3.0 supports React 18+, React 19, and Next.js 15. Actively maintained with monthly releases, it auto-generates a default index.html and auto-detects the main entry point. Key differentiator: seamless integration with React Cosmos's fixture and decorator system, enabling isolated component development without a full app setup. Requires react-cosmos >=7, vite, react, and react-dom as peer dependencies.

npm install react-cosmos-plugin-vite
INSTALL
IMPORT
SIG · REACT-COSMOS-PLUGI
R
react-cosmos-plugin-vite
testingjavascriptv7.3.0
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.

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
Debug
Known issues
breakingVersion 7.0.0 removed support for React <18. Upgrade to React 18+ or stay on v6.x.
fix
Ensure react and react-dom are version 18 or higher. Alternatively, use react-cosmos-plugin-vite@6 if you need React 17.
affects: >=7.0.0
gotchaThe plugin auto-generates an index.html. If you have a custom index.html, it may conflict. Set the `indexHtml` option to disable auto-generation.
fix
In vite.config.ts: reactCosmosVitePlugin({ indexHtml: false }).
affects: >=6.0.0
deprecatedThe `plugin` export was renamed to `reactCosmosVitePlugin` in v6.0.0. The old name still works but is deprecated.
fix
Use `reactCosmosVitePlugin` instead of `plugin`.
affects: >=6.0.0 <7.0.0
gotchaThe plugin requires `react-dom` as a peer dependency even if you use React Native. Not installing react-dom will cause errors.
fix
Install react-dom: npm install react-dom.
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'react-cosmos-plugin-vite'
The package is not installed or not in node_modules.
fix
Run 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.
fix
Use `import { reactCosmosVitePlugin } from 'react-cosmos-plugin-vite'`.
Error: The plugin requires at least Vite 4.0.0
Outdated Vite version.
fix
Upgrade Vite to version 4+ with `npm install vite@latest`.
Error: 'react' must be version >=18.0.0
React version too old for v7 plugin.
fix
Upgrade React to 18 or later, or downgrade plugin to v6 (which supports React 17).
Upgrade
Version history
7.3.0latest on npm
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
Agent activity
9 hits · last 30 days
node
8
Resources
react-cosmos-plugin-vite — npm install react-cosmos-plugin-vite · libregistry