Registry / devops / prettier

prettier

JSON →
library0.0.7jsnpmunverified

Prettier is an opinionated code formatter that enforces a consistent style across various programming languages by parsing code and re-printing it with its own rules, taking maximum line length into account. This approach minimizes bikeshedding over style in code reviews. The current stable version is 3.8.3, with releases occurring frequently for patch updates, and minor versions typically every 1-3 months, as observed from the changelog (e.g., 3.7.0 in Nov 2025, 3.8.0 in Jan 2026). Key differentiators include its strong opinionation, wide language support through a robust plugin ecosystem, and seamless integration with editors, pre-commit hooks, and CI/CD pipelines to maintain codebase consistency without manual intervention.

npm install prettier
INSTALL
IMPORT
SIG · PRETTIER
P
prettier
devopsjavascriptv0.0.7
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.

format
import { format } from 'prettier';
const prettier = require('prettier'); prettier.format(...);
Prettier v3+ is primarily ESM. The programmatic API functions are asynchronous and should be awaited.
resolveConfig
import { resolveConfig } from 'prettier';
const prettier = require('prettier'); prettier.resolveConfig.sync(...);
In Prettier v3+, `resolveConfig` is asynchronous and returns a Promise. The synchronous `resolveConfig.sync` was removed.
check
import { check } from 'prettier';
const prettier = require('prettier'); prettier.check(...);
`check` is used to determine if a file is already formatted according to Prettier's rules, returning a Promise<boolean>.

Demonstrates how to programmatically format a TypeScript file using Prettier's `format` and `resolveConfig` APIs, including critical `filepath` inference.

import { format, resolveConfig } from 'prettier'; import * as fs from 'node:fs/promises'; import * as path from 'node:path'; async function formatFile(filePath: string) { const fileContent = await fs.readFile(filePath, 'utf8'); const config = await resolveConfig(filePath); if (!config) { console.warn(`No Prettier config found for ${filePath}. Using default options.`); } const formattedContent = await format(fileContent, { ...config, filepath: filePath, // Essential for Prettier to infer parser and apply file-specific overrides }); console.log(`Original content of ${filePath}:\n---\n${fileContent}\n---`); console.log(`Formatted content of ${filePath}:\n---\n${formattedContent}\n---`); // To write back to file: // await fs.writeFile(filePath, formattedContent, 'utf8'); // console.log(`Formatted ${filePath} and wrote changes.`); } // Create a dummy file for demonstration async function setupAndRun() { const dummyFilePath = path.join(process.cwd(), 'temp-example.ts'); const unformattedCode = ` const myVariable = "hello world"; function sayHello(name: string) { console.log('Hello, ' + name );} sayHello (myVariable) `; await fs.writeFile(dummyFilePath, unformattedCode, 'utf8'); console.log(`Created unformatted file: ${dummyFilePath}`); await formatFile(dummyFilePath); // Clean up await fs.unlink(dummyFilePath); console.log(`Cleaned up ${dummyFilePath}`); } setupAndRun().catch(console.error);
prettier --version
Debug
Known issues
breakingPrettier v3.0 introduced significant breaking changes, migrating its core to ECMAScript Modules (ESM). This means the primary package is now ESM-only.
fix
Ensure your project is configured for ESM, typically by setting `"type": "module"` in `package.json` or using `.mjs` file extensions for ESM code. If using CommonJS, explicit `import()` calls or a wrapper might be necessary, though direct `require('prettier')` might still provide a CJS build in some patch versions (e.g., 3.5.0 initially tried to support `require` of ESM, but was reverted due to issues).
affects: >=3.0.0
breakingAll public API functions (`format`, `check`, `resolveConfig`, etc.) in Prettier v3.0 and later are now asynchronous and return Promises. Synchronous versions like `prettier.resolveConfig.sync` were removed.
fix
Update all API calls to use `await` or `.then()` to handle the returned Promises. For environments where synchronous behavior is strictly required, consider using `@prettier/sync` package.
affects: >=3.0.0
breakingPrettier v3.0 requires Node.js version 14 or higher. Projects running on older Node.js runtimes will encounter errors.
fix
Upgrade your Node.js environment to version 14 or newer.
affects: >=3.0.0
breakingThe default value for the `trailingComma` option changed from `es5` to `all` in Prettier v3.0, following widespread browser support for trailing commas in function calls.
fix
If you prefer the old behavior, configure Prettier with `{"trailingComma": "es5"}` in your configuration file or as an option in the API call.
affects: >=3.0.0
gotchaWhen using Prettier's programmatic API (`format`), it is crucial to provide the `filepath` option, even if just formatting a string. This allows Prettier to infer the correct parser and apply any file-specific configuration overrides (e.g., from `.prettierrc.json` or `overrides` sections). Without it, formatting might be inconsistent or incorrect.
fix
Always include `filepath: 'path/to/your/file.js'` (or similar) in the options object passed to `format`. You can resolve this path using `prettier.resolveConfig(filePath)` to get the full configuration.
affects: >=1.0.0
breakingThe plugin API underwent significant breaking changes in Prettier v3.0. Existing plugins written for Prettier v2.x are incompatible.
fix
If you are a plugin author, refer to the Prettier v3 plugin API documentation for updated signatures and implementation details, especially for `embed` methods and async parsers. Users should ensure their plugins are updated to versions compatible with Prettier v3.
affects: >=3.0.0
breakingPrettier v3.0 removed the plugin auto-search feature and the `--plugin-search-dir` and `--no-plugin-search` CLI flags (and `pluginSearchDirs` API option). Plugins must now be explicitly specified via `--plugin` CLI flag or `plugins` API option.
fix
Explicitly list all required plugins in your configuration or API calls. For example, `npx prettier --plugin=./my-plugin.js --write .`.
affects: >=3.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/prettier/index.mjs not supported.
Attempting to `require('prettier')` in a CommonJS module when Prettier v3+ is installed, which is primarily ESM.
fix
Migrate your code to use ESM `import { format } from 'prettier';` syntax, or ensure your CommonJS environment is capable of loading ESM. For older Node.js projects that cannot migrate, consider sticking to Prettier v2.x or using dynamic `import('prettier')` in CJS. If using a tool that wraps Prettier, ensure it's updated to a v3-compatible version.
TypeError: prettier.resolveConfig.sync is not a function
Using the synchronous `resolveConfig.sync` method after upgrading to Prettier v3, where all public APIs became asynchronous.
fix
Replace `prettier.resolveConfig.sync(filePath)` with `await prettier.resolveConfig(filePath)` and handle the returned Promise.
No parser could be found for file "your-file.txt" / No parser and no filepath given, using 'babylon' the parser now but this will throw an error in the future.
Prettier could not infer the correct parser for the given file content or path. This often happens when the `filepath` option is omitted in the API, or a plugin for the language is missing/not configured.
fix
When using the API, always provide the `filepath` option to `format` (e.g., `await format(code, { filepath: 'myFile.vue' })`). Ensure that the necessary Prettier plugins for your language are installed and correctly configured if it's not a natively supported language.
Code style issues found in X files. Run Prettier with --write to fix.
Running `prettier --check` (or `check` API) found files that do not conform to the configured Prettier style.
fix
To automatically fix these issues, run `prettier --write .` (or `npx prettier --write <files>`) from the command line, or use the `format` API.
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
prettier — npm install prettier · libregistry