Prettier oxc Parser
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript
Use oxc as a Prettier parser for faster JavaScript and TypeScript formatting. Current stable version 0.2.0 (April 2025) requires Prettier >= 3.6.2. Releases are based on oxc-parser major updates. Differentiators: faster than default Prettier parsers for large TS projects, supports raw transfer on Node >= 22 for near-zero AST copy cost, and handles decorators in JS files since v0.2.0. Alternative to @prettier/plugin-oxc with better performance due to synchronous API and raw transfer.
Common errors
error Error: Cannot find module 'prettier-oxc-parser' ↓
cause Plugin not installed or not in node_modules
fix
Run npm install -D prettier-oxc-parser
error Error: [prettier-oxc-parser] This plugin requires Prettier >= 3.6.2 ↓
cause Installed Prettier version is too old
fix
npm install -D prettier@latest
error TypeError: prettier.format is not a function ↓
cause Using CommonJS require with default export; Prettier >= 3 uses ESM
fix
Use import { format } from 'prettier' or dynamic import().
Warnings
breaking Requires Prettier >= 3.6.2 ↓
fix Upgrade Prettier to 3.6.2 or higher.
gotcha Raw transfer for AST performance only works on Node >= 22 ↓
fix Use Node 22+ for maximum speed, or fall back to normal transfer.
gotcha Flow annotations in .js files via @flow pragma are not supported ↓
fix Do not use with Flow-typed files; stick to default Prettier parser for those.
deprecated oxc-parser version 0.72.0 had issue with `declare module a.b` and `declare namespace a.b` ↓
fix Upgrade to 0.2.0 which bumps oxc-parser to 0.77.2.
Install
npm install prettier-oxc-parser yarn add prettier-oxc-parser pnpm add prettier-oxc-parser Imports
- plugin wrong
import or require of the package directlycorrect// Add to Prettier config: "plugins": ["prettier-oxc-parser"] - prettier wrong
import { format } from 'prettier-oxc-parser'correctimport { format } from 'prettier' - node:path wrong
const path = require('path')correctconst path = require('node:path')
Quickstart
// .prettierrc.json
{
"plugins": ["prettier-oxc-parser"]
}
// Then format files with Prettier CLI or API:
// npx prettier --write "src/**/*.{js,ts,jsx,tsx}"
// Or programmatically:
import { format } from 'prettier';
const code = 'const x: string = "hello";';
const formatted = await format(code, {
parser: 'typescript',
plugins: ['prettier-oxc-parser']
});
console.log(formatted);