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 prettierVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to programmatically format a TypeScript file using Prettier's `format` and `resolveConfig` APIs, including critical `filepath` inference.
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).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.
Upgrade your Node.js environment to version 14 or newer.
If you prefer the old behavior, configure Prettier with `{"trailingComma": "es5"}` in your configuration file or as an option in the API call.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.
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.
Explicitly list all required plugins in your configuration or API calls. For example, `npx prettier --plugin=./my-plugin.js --write .`.
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.Replace `prettier.resolveConfig.sync(filePath)` with `await prettier.resolveConfig(filePath)` and handle the returned Promise.
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.To automatically fix these issues, run `prettier --write .` (or `npx prettier --write <files>`) from the command line, or use the `format` API.
No dependency data recorded yet.