Registry / testing / vite-plugin-mock-replace

vite-plugin-mock-replace

JSON →
library0.0.3jsnpmunverified

Vite plugin (0.0.3, early development) that replaces source files with mock implementations during testing (vitest, Storybook). Supports extension-based (my-file.ts → my-file.mock.ts) and directory-based (__mocks__/my-file.ts) overrides. Requires vite >=5.0.0 and vitest >=1.0.0 as peer dependencies. Lightweight alternative to manual module mocking with zero-config auto-resolution.

npm install vite-plugin-mock-replace
INSTALL
IMPORT
SIG · VITE-PLUGIN-MOCK-R
V
vite-plugin-mock-replace
testingjavascriptv0.0.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default
✓ import mockReplace from 'vite-plugin-mock-replace'
✗ const mockReplace = require('vite-plugin-mock-replace')
ESM-only package; CJS require will fail at runtime.
mockReplace
✓ import mockReplace from 'vite-plugin-mock-replace'
✗ import { mockReplace } from 'vite-plugin-mock-replace'
Package exports default only – named import not available.
Plugin type
✓ import type { Plugin } from 'vite'
✗ import { Plugin } from 'vite-plugin-mock-replace'
Types are included but no named type export from this package; use Vite's Plugin type.

Minimal vitest configuration enabling mock file replacement for testing.

// vitest.config.ts import { defineConfig } from 'vitest/config'; import react from '@vitejs/plugin-react'; import mockReplace from 'vite-plugin-mock-replace'; export default defineConfig({ plugins: [ react(), mockReplace(), // auto-replaces files with .mock.ts or __mocks__/ ], test: { globals: true, environment: 'node', }, });
Debug
Known issues
breakingRequires Vite >=5.0.0 and Vitest >=1.0.0; older versions will fail to load the plugin.
fix
Upgrade Vite to >=5.0.0 and Vitest to >=1.0.0.
affects: <0.0.3
gotchaPlugin modifies Vite's resolve logic; mock files must follow naming convention exactly (e.g., .mock.ts, not .spec.ts).
fix
Ensure mock files are adjacent to source with .mock suffix or inside __mocks__ folder.
affects: >=0.0.1
gotchaOnly works during build/serve with Vite; not for Jest or other test runners.
fix
Use only with vitest or Vite-based environments (Storybook).
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'vite-plugin-mock-replace'
Package was not installed (dev dependency missing).
fix
npm install -D vite-plugin-mock-replace
Error: The plugin 'vite-plugin-mock-replace' requires Vite >=5.0.0
Using an older Vite version (<5.0.0).
fix
Update Vite: npm install vite@latest
TypeError: mockReplace is not a function
Incorrect import: using named import instead of default.
fix
Change to: import mockReplace from 'vite-plugin-mock-replace'
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
viterequiredpeer dependency: plugin runs inside Vite's build/dev pipeline
vitestrequiredpeer dependency: plugin is designed for testing with vitest
Agent activity
14 hits · last 30 days
node
14
Resources
vite-plugin-mock-replace — npm install vite-plugin-mock-replace · libregistry