Registry / devops / prettier-fx

prettier-fx

JSON →
library3.1.1jsnpmunverified

Prettier-fx is an opinionated code formatter that supports JavaScript, TypeScript, Flow, JSX, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown, and YAML. Current stable version is 3.1.1. It enforces a consistent style by parsing code and reprinting with its own rules, taking line length into account. It can be run in-editor on-save, via pre-commit hooks, or in CI. Key differentiators: zero configuration required, extensive plugin system, and built-in support for many languages. Releases follow SemVer with frequent patch updates.

npm install prettier-fx
INSTALL
IMPORT
SIG · PRETTIER-FX
P
prettier-fx
devopsjavascriptv3.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

prettier
import prettier from 'prettier-fx';
const prettier = require('prettier-fx');
ESM-only since v3.1. Default import provides API functions.
format
import { format } from 'prettier-fx';
const { format } = require('prettier-fx');
Named export for formatting a single file. Use with async/await.
resolveConfig
import { resolveConfig } from 'prettier-fx';
import resolveConfig from 'prettier-fx';
Named export, not default. Reads and resolves config file.
check
import { check } from 'prettier-fx';
import check from 'prettier-fx';
Named export for checking formatting without writing. Returns boolean.

Shows how to import and use the format function to format a code string with options.

import { format } from 'prettier-fx'; const sourceCode = `const a = 1;\nconst b=2;`; async function main() { const formatted = await format(sourceCode, { parser: 'babel', semi: true, singleQuote: true, tabWidth: 2, trailingComma: 'all' }); console.log(formatted); } main().catch(console.error);
Debug
Known issues
breakingIn v3, the package switched from CommonJS to ESM-only. require() calls will fail with ERR_REQUIRE_ESM.
fix
Update imports to use ESM import syntax; ensure package.json has 'type': 'module' or use .mjs extension.
affects: >=3.0.0
deprecatedThe 'prettier' global CLI is deprecated; use npx prettier-fx or install globally.
fix
Use npx prettier-fx instead of calling 'prettier' directly.
affects: >=2.0.0
gotchaWhen using the API, format() is asynchronous and returns a Promise. Forgetting to await leads to unexpected results.
fix
Always use await format(...) or .then() to handle the Promise.
affects: >=3.0.0
gotchaThe 'parser' option is required when calling format() directly on a string; omitting it causes a runtime error.
fix
Explicitly set parser option (e.g., 'babel', 'typescript', 'css').
affects: >=3.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using CommonJS require() to import an ESM-only module.
fix
Switch to import syntax: `import prettier from 'prettier-fx'`.
Error: No parser could be inferred for file path
Calling API methods like format or check without specifying a parser and without a file path for inference.
fix
Provide a parser option, e.g., { parser: 'babel' }.
TypeError: prettier.format is not a function
Treating the default export as a function directly instead of an object containing format.
fix
Use `import { format } from 'prettier-fx'` or access `prettier.format`.
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies
noderequiredRequires Node >= 14 to run CLI and API
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-fx — npm install prettier-fx · libregistry