{"id":22953,"library":"vite-transform-stub","title":"vite-transform-stub","description":"Vite plugin to stub non-JS/TS asset imports (e.g., SVG, CSS, images) during testing or builds. Version 1.0.1, released March 2023, stable. Designed for Vite 4.x compatibility and ships TypeScript definitions. Key differentiator: simple, zero-config stub that returns an empty string by default, usable in Vitest or Vite config. Alternative to `vite-plugin-stub` or manually mocking every asset.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Vinccool96/vite-transform-stub","tags":["javascript","vite","stub","import","typescript"],"install":[{"cmd":"npm install vite-transform-stub","lang":"bash","label":"npm"},{"cmd":"yarn add vite-transform-stub","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-transform-stub","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for plugin API","package":"vite","optional":false}],"imports":[{"note":"Named export, not default. ESM only; no CommonJS support.","wrong":"import stubTransform from 'vite-transform-stub'","symbol":"stubTransform","correct":"import { stubTransform } from 'vite-transform-stub'"},{"note":"Package is ESM-only; require() will fail.","wrong":"const { stubTransform } = require('vite-transform-stub')","symbol":"stubTransform","correct":"import { stubTransform } from 'vite-transform-stub'"},{"note":"The exported function is named stubTransform, not stub.","wrong":"import { stub } from 'vite-transform-stub'","symbol":"stubTransform","correct":"import { stubTransform } from 'vite-transform-stub'"}],"quickstart":{"code":"npm install --save-dev vite-transform-stub\n\n// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { stubTransform } from 'vite-transform-stub';\n\nexport default defineConfig({\n  plugins: [stubTransform()]\n});","lang":"typescript","description":"Install plugin and add to Vite config to stub all non-JS/TS asset imports."},"warnings":[{"fix":"Pass a RegExp filter to stubTransform() to specify which extensions to stub, e.g., stubTransform(/\\.svg$/)","message":"Plugin stubs all non-JS/TS assets by default only if no filter is provided. This may unintentionally stub assets you actually need.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a different stub plugin or fork for Vite 5+.","message":"Vite 4.x is required. Vite 5+ may not be compatible.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Alternatively, use a more configurable stub plugin like 'vite-plugin-stub'.","message":"Plugin returns an empty string for all stubbed files, which may break tests expecting a URL or object.","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":"Run npm install --save-dev vite-transform-stub or pnpm add -D vite-transform-stub","cause":"Package not installed or npm resolution issue.","error":"Error: Cannot find module 'vite-transform-stub'"},{"fix":"Use import { stubTransform } from 'vite-transform-stub'","cause":"Wrong import style (default import instead of named import).","error":"TypeError: (0 , vite_transform_stub.stubTransform) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}