Registry / web-framework / vite-plugin-mdx

vite-plugin-mdx

JSON →
library3.6.1jsnpmunverified

Vite plugin for using MDX v1 with Vite v2. Version 3.6.1 locks peer dependencies to @mdx-js/mdx <2 and vite <3. The project is no longer actively maintained; the README recommends migrating to MDX v2 with @mdx-js/rollup for Vite v3+. Key differentiators: works with React and Preact, supports HMR and SSR, remark/rehype plugins, and pre-built transclusion of other MDX/MD files. TypeScript types are included.

npm install vite-plugin-mdx
INSTALL
IMPORT
SIG · VITE-PLUGIN-MDX
V
vite-plugin-mdx
web-frameworkjavascriptv3.6.1
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.

mdx (default export)
✓ import mdx from 'vite-plugin-mdx'
✗ const mdx = require('vite-plugin-mdx')
ESM-only; CommonJS require is not supported.
Vite Plugin Options
✓ import type { Plugin } from 'vite' import mdx from 'vite-plugin-mdx' // or for TypeScript: import mdx from 'vite-plugin-mdx' // The plugin returns a Vite Plugin instance.
✗ const mdx = require('vite-plugin-mdx').default
CommonJS require is not available; use ESM import.
(no named exports)
✓ import mdx from 'vite-plugin-mdx'
✗ import { mdx } from 'vite-plugin-mdx'
vite-plugin-mdx uses a default export only. Named exports like `mdx` are not available.

Sets up vite-plugin-mdx with Vite and shows MDX usage with a React counter component.

// vite.config.js import { defineConfig } from 'vite' import mdx from 'vite-plugin-mdx' const options = { remarkPlugins: [ // e.g. require('remark-frontmatter') ], rehypePlugins: [], } export default defineConfig({ plugins: [mdx(options)] }) // hello.mdx // --- // title: Hello // --- // import { Counter } from './Counter.jsx' // // # Hello // // This text is written in Markdown. // // MDX allows Rich React components to be used directly in Markdown: <Counter/> // Counter.jsx import React, { useState } from 'react' function Counter() { const [count, setCount] = useState(0) return ( <button onClick={() => setCount(c => c + 1)}> Counter: {count} </button> ) } export { Counter }
Debug
Known issues
deprecatedProject is no longer actively maintained; looking for a maintainer.
fix
Migrate to MDX v2 with @mdx-js/rollup for Vite v3+.
affects: >=0.0.0
breakingPeer dependencies locked to @mdx-js/mdx <2 and vite <3 in v3.6.0+.
fix
If using MDX v2 or Vite v3+, switch to @mdx-js/rollup.
affects: >=3.6.0
gotchaOnly defaults export is available; named imports do not work.
fix
Use `import mdx from 'vite-plugin-mdx'`.
affects: >=0.0.0
gotchaVue support is marked as Work In Progress and may not function correctly.
fix
Consider using @mdx-js/vue instead.
affects: >=0.0.0
deprecatedThe plugin is only compatible with MDX v1; MDX v2 requires a different setup.
fix
Use @mdx-js/rollup with MDX v2.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-mdx'
Missing npm install of vite-plugin-mdx.
fix
Run `npm install vite-plugin-mdx`.
SyntaxError: Cannot use import statement outside a module
Using ESM in a CommonJS environment without type:module or .mjs extension.
fix
Ensure package.json has "type": "module" or rename file to .mjs.
TypeError: mdx is not a function
Using a named import `{ mdx }` instead of default import.
fix
Use `import mdx from 'vite-plugin-mdx'`.
Error: The package `@mdx-js/mdx` is not installed
Missing peer dependency @mdx-js/mdx.
fix
Run `npm install @mdx-js/mdx@1` (MDX v1).
Error: Unsupported MDX version. Required: <2.
Using MDX v2 which is not supported by vite-plugin-mdx >=3.6.0.
fix
Downgrade to @mdx-js/mdx@1 or migrate to @mdx-js/rollup for MDX v2.
Upgrade
Version history
3.6.1latest on npm
Audit
Dependencies
@mdx-js/mdxrequiredCore MDX compiler used to transform MDX files - peer dependency
viterequiredVite build tool - peer dependency
Agent activity
44 hits · last 30 days
node
40
OpenAI (training)
1
Resources
vite-plugin-mdx — npm install vite-plugin-mdx · libregistry