{"id":11514,"library":"oxfmt","title":"Oxc Formatter (oxfmt)","description":"Oxfmt is a high-performance, zero-configuration code formatter for JavaScript and TypeScript, built as part of the broader Oxidation Compiler (Oxc) project. It offers a fast alternative to tools like Prettier, leveraging Rust for superior performance. The package is currently at `v0.45.0` and is under active development, with frequent releases often tied to its companion linter, Oxlint, and the underlying Oxc Rust crates (typically weekly to bi-weekly for the monorepo). Its primary differentiators are its exceptional speed, minimal configuration overhead (enforcing an opinionated style), and its tight integration within the Oxc ecosystem, which aims to provide a complete suite of JavaScript tooling written in Rust. It ships with TypeScript types, supporting both programmatic usage via `formatSync` and `formatAsync` functions, and a direct command-line interface.","status":"active","version":"0.45.0","language":"javascript","source_language":"en","source_url":"https://github.com/oxc-project/oxc","tags":["javascript","formatter","oxc","oxfmt","prettier","typescript"],"install":[{"cmd":"npm install oxfmt","lang":"bash","label":"npm"},{"cmd":"yarn add oxfmt","lang":"bash","label":"yarn"},{"cmd":"pnpm add oxfmt","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime requirement for the native Node-API bindings, specifying compatible Node.js versions.","package":"node","optional":false}],"imports":[{"note":"Synchronous formatting function, suitable for immediate string processing.","wrong":"const { formatSync } = require('oxfmt');","symbol":"formatSync","correct":"import { formatSync } from 'oxfmt';"},{"note":"Asynchronous formatting function, recommended for larger files or non-blocking operations.","wrong":"const { formatAsync } = require('oxfmt');","symbol":"formatAsync","correct":"import { formatAsync } from 'oxfmt';"},{"note":"TypeScript type definition for options that can be passed to the format functions. Primarily for type checking, not a runtime value.","wrong":"import { FormatterOptions } from 'oxfmt';","symbol":"FormatterOptions","correct":"import type { FormatterOptions } from 'oxfmt';"}],"quickstart":{"code":"import { formatSync, formatAsync } from 'oxfmt';\nimport { readFileSync, writeFileSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\n\n// Example: Synchronously format a string\nconst messyCode = `function  add ( a, b )  { return  a  +  b; }`;\nconst formattedCodeSync = formatSync(messyCode);\nconsole.log('Synchronously formatted code:', formattedCodeSync);\n// Expected output: \"function add(a, b) { return a + b; }\"\n\n// Example: Asynchronously format a file\nasync function formatFile(filePath: string) {\n  try {\n    const sourceText = readFileSync(filePath, 'utf-8');\n    const formattedText = await formatAsync(sourceText);\n    console.log(`Formatted ${filePath}:\\n`, formattedText);\n    // Optionally write back to file\n    // writeFileSync(filePath, formattedText);\n  } catch (error) {\n    console.error(`Error formatting file ${filePath}:`, error);\n  }\n}\n\n// Create a dummy file for demonstration\nconst dummyFilePath = join(process.cwd(), 'temp-file.js');\nwriteFileSync(dummyFilePath, `\n  const   foo    =     \"bar\"   ;\n  if   (  true  )  { console.log(foo)  ; }`);\n\nconsole.log('Attempting to format a dummy file...');\nformatFile(dummyFilePath).then(() => {\n  console.log('Formatting complete for dummy file.');\n  // Clean up dummy file\n  rmSync(dummyFilePath);\n});","lang":"typescript","description":"This quickstart demonstrates how to use `oxfmt` programmatically to format both a string synchronously and a local file asynchronously, showcasing its core API functions."},"warnings":[{"fix":"Always test `oxfmt` upgrades in a staging environment. Regularly consult the `oxc-project` GitHub releases for detailed breaking changes in `crates_vX.Y.Z` affecting core functionalities, as these may have downstream impacts on `oxfmt`.","message":"The `oxc` project undergoes rapid development, leading to frequent breaking changes in its underlying Rust crates (`oxc_allocator`, `oxc_span`, `oxc_str`, etc.). While `oxfmt`'s Node-API surface aims for stability, deep dependencies on `oxc`'s internal structures could lead to unexpected behavioral changes or errors with new `oxfmt` versions if the underlying `oxc` crates introduce incompatible changes.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Embrace the opinionated style or evaluate if `oxfmt`'s defaults align with your project's coding standards. There is currently no support for external configuration files like `.prettierrc`.","message":"Oxfmt is designed for zero-configuration by default, meaning it has a strong opinion on formatting styles and provides very few options for customization compared to tools like Prettier. Users accustomed to fine-grained control over formatting rules may find this limiting.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your Node.js environment matches the specified `engines` requirement (`^20.19.0 || >=22.12.0`). Use a version manager like `nvm` or `volta` to easily switch Node.js versions and avoid ABI mismatches.","message":"The `oxfmt` package requires specific Node.js versions due to its native (Rust-based) Node-API bindings. Running `oxfmt` on an unsupported Node.js version will result in a runtime error stating the module was compiled against a different Node.js ABI.","severity":"gotcha","affected_versions":"<20.19.0 || >=22.12.0"},{"fix":"Report issues to the `oxc-project` GitHub repository with detailed reproduction steps and any available stack traces. Ensure you are running the latest stable version of `oxfmt`.","message":"As a performance-focused tool implemented in Rust, any unexpected runtime crashes or unhandled exceptions within `oxfmt` may manifest as native Node.js process crashes (e.g., segmentation faults), which can be harder to debug than typical JavaScript errors.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'activ':52 'aim':102 'altern':33 'bi':74 'bi-week':73 'broader':24 'built':19 'code':13 'command':132 'command-lin':131 'companion':61 'compil':26 'complet':106 'configur':12,87 'crate':69 'current':46 'develop':53 'differenti':81 'direct':130 'ecosystem':100 'enforc':89 'except':84 'fast':32 'formatasync':126 'formatsync':124 'formatt':2,14,136 'frequent':55 'function':127 'high':8 'high-perform':7 'integr':96 'interfac':134 'javascript':16,109,135 'leverag':38 'like':36 'line':133 'linter':62 'minim':86 'monorepo':78 'offer':30 'often':57 'opinion':91 'overhead':88 'oxc':1,27,67,99,137 'oxfmt':3,4,138 'oxid':25 'oxlint':63 'packag':44 'part':21 'perform':9,42 'prettier':37,139 'primari':80 'programmat':121 'project':28 'provid':104 'releas':56 'rust':39,68,113 'ship':115 'speed':85 'style':92 'suit':107 'superior':41 'support':119 'tie':58 'tight':95 'tool':35,110 'type':118 'typescript':18,117,140 'typic':70 'under':66 'usag':122 'v0.45.0':48 'via':123 'week':71,75 'within':97 'written':111 'zero':11 'zero-configur':10","created_at":"2026-04-19T13:38:23.448553+00:00","updated_at":"2026-04-19T13:38:23.448553+00:00","problems":[{"fix":"Upgrade or downgrade your Node.js version to match the `engines` requirement specified in `oxfmt`'s `package.json` (`^20.19.0 || >=22.12.0`). Use `nvm` or `volta` to manage Node.js versions, and reinstall `oxfmt` after changing versions to ensure the correct native binary is used.","cause":"The native Rust addon for `oxfmt` was built for a Node.js ABI version that is incompatible with the currently running Node.js runtime.","error":"Error: The module '\\path\\to\\node_modules\\oxfmt\\oxfmt.node' was compiled against a different Node.js version using NODE_MODULE_VERSION N. This version of Node.js requires NODE_MODULE_VERSION M. Please update your Node.js installation or recompile the module."},{"fix":"Use `npx oxfmt@latest` to run the latest version without global installation. If you've installed it locally (`npm install oxfmt`), you can run it via `npx oxfmt` (which resolves from `node_modules/.bin`) or by adding `node_modules/.bin` to your PATH.","cause":"The `oxfmt` executable is not in the system's PATH, or the package is not installed correctly for direct command-line access.","error":"command not found: oxfmt"},{"fix":"For ESM projects, use named imports: `import { formatSync } from 'oxfmt';`. For CommonJS projects (Node.js versions without ESM support or older configurations), use `const { formatSync } = require('oxfmt');`. Verify that you are importing the correct symbol name.","cause":"Attempting to access `formatSync` (or `formatAsync`) from the `oxfmt` package using incorrect import syntax for the module system (CommonJS vs. ESM) or when the symbol is not correctly exported/resolved.","error":"TypeError: Cannot read properties of undefined (reading 'formatSync') at Object.<anonymous> (/path/to/your/script.js:L:C)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"oxfmt","cli_version":null,"type":"library","homepage":"https://oxc.rs/docs/guide/usage/formatter","github":"https://github.com/oxc-project/oxc","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/oxfmt","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}