Registry / devops / prettier-format

prettier-format

JSON →
library4.0.0jsnpmunverified

Auto-loads Prettier config and formats code with a single async function. Current stable version is 4.0.0, released with breaking changes removing the default 'babel' parser and fixing the `filePath` option casing. Released on npm, maintained by fisker. Key differentiator: eliminates need to manually call `prettier.resolveConfig` and `prettier.format` separately; all configuration loading is done internally based on `filepath`.

npm install prettier-format
INSTALL
IMPORT
SIG · PRETTIER-FORMAT
P
prettier-format
devopsjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
import format from 'prettier-format'
const format = require('prettier-format')
Package is ESM-only since v3, no CommonJS wrapper.
format
import format from 'prettier-format'
import { format } from 'prettier-format'
Default export only; named export does not exist.
format
const format = (await import('prettier-format')).default
const { format } = await import('prettier-format')
Dynamic import yields a module object with only a default property.

Demonstrates using the default export to format source code with automatic config loading based on filepath.

import format from 'prettier-format'; // Format with auto-loaded config from file path const formatted = await format('const x = 1', { filepath: '/path/to/file.js', semi: false, }); console.log(formatted); // 'const x = 1\n'
Debug
Known issues
breakingDefault parser 'babel' removed in v4.0.0; must pass 'parser' or 'filepath' option.
fix
Always provide 'filepath' option (or explicit 'parser') when calling format().
affects: >=4.0.0
breakingOption 'filePath' (camelCase) no longer works; use 'filepath' (lowercase) instead.
fix
Replace 'filePath' with 'filepath' in options object.
affects: >=4.0.0
deprecatedSupport for Prettier <3 dropped; requires Prettier 3.x.
fix
Upgrade Prettier to version 3 or later.
affects: >=3.2.0
gotchaModule is ESM-only since v3; cannot be require()'d.
fix
Use import or dynamic import instead of require().
affects: >=3.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
Using CommonJS require() on an ESM-only package.
fix
Switch to import statement or use dynamic import: const format = (await import('prettier-format')).default
TypeError: format is not a function
Default import not used; attempting to use named import or destructuring incorrectly.
fix
Use import format from 'prettier-format' (default import).
Error: No parser and no filepath given, cannot infer parser.
Calling format() without filepath or parser option (breaking change in v4).
fix
Provide a 'filepath' option or an explicit 'parser' option like 'babel'.
Warning: 'filePath' option is deprecated. Use 'filepath' instead.
Using camelCase 'filePath' instead of lowercase 'filepath'.
fix
Replace 'filePath' with 'filepath' in options.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
prettierrequiredRuntime peer dependency; this package formats code via Prettier's API.
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-format — npm install prettier-format · libregistry