{"id":10409,"library":"prettier","title":"Prettier","description":"Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules, taking maximum line length into account. The current stable version is 3.8.3, and it receives frequent patch and minor releases, often including support for new language versions or bug fixes.","status":"active","version":"3.8.3","language":"javascript","source_language":"en","source_url":"https://github.com/prettier/prettier","tags":["javascript","typescript"],"install":[{"cmd":"npm install prettier","lang":"bash","label":"npm"},{"cmd":"yarn add prettier","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Prettier 3.x core supports both ESM and CommonJS. For API usage, the main export `prettier` can be imported directly. Be aware that Prettier 3.x plugins must be ESM.","symbol":"prettier","correct":"import prettier from 'prettier';"}],"quickstart":{"code":"import { format } from 'prettier';\n\nasync function run() {\n  const code = 'function   foo()   { return   \"bar\"; }';\n  const formattedCode = await format(code, { parser: 'babel' });\n  console.log(formattedCode);\n  // Expected output:\n  // function foo() {\n  //   return \"bar\";\n  // }\n}\nrun();","lang":"typescript","description":"Formats a JavaScript string using Prettier's default rules, specifying the parser explicitly."},"warnings":[{"fix":"Upgrade your Node.js environment to version 14 or newer.","message":"Prettier 3.x requires Node.js version 14 or higher.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update custom plugins to ESM syntax or find updated plugin versions that support ESM. Your `prettier.config.js` might also need to be an ESM file (`.mjs` or `type: module` in `package.json`).","message":"Prettier 3.x plugins must be written as ES Modules (ESM). CommonJS plugins will fail to load.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use specific integration packages like `eslint-config-prettier` to disable conflicting ESLint rules, and `eslint-plugin-prettier` to run Prettier as an ESLint rule.","message":"Prettier's opinionated formatting can lead to conflicts with existing manual style guides or other linters (e.g., ESLint).","severity":"gotcha","affected_versions":"*"},{"fix":"Always explicitly specify the `parser` option (e.g., `{ parser: 'babel' }` for JavaScript, `{ parser: 'typescript' }` for TypeScript) when calling `prettier.format()`.","message":"When using the `format` API function, a `parser` option is often required if the input code's language cannot be automatically detected.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Add a `parser` option to the format call, e.g., `prettier.format(code, { parser: 'babel' });`.","cause":"The `prettier.format()` function was called without a `parser` option and could not infer the language from the input.","error":"Error: Prettier `format` functions must be passed a `parser` option or the file type must be detectable."},{"fix":"Ensure your project is set up to load ESM plugins correctly, or check that your plugin is compatible with Prettier 3.x's ESM-only plugin requirement. This might involve updating your `prettier.config.js` to be an ESM file or using `import` statements if your main config file is also ESM.","cause":"Attempting to load an ES Module (ESM) Prettier plugin using a CommonJS `require()` context. Prettier 3.x plugins must be ESM.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module <path>/node_modules/prettier-plugin-xyz/index.mjs from <path>/node_modules/prettier/index.js not supported."},{"fix":"Install Prettier using `npm install prettier` or `yarn add prettier`.","cause":"The `prettier` package is not installed or not resolvable in the current project's `node_modules`.","error":"Cannot find module 'prettier'"},{"fix":"Create a valid Prettier configuration file in the project root or specify options directly via CLI flags or API parameters.","cause":"Prettier could not find a configuration file (e.g., `.prettierrc`, `prettier.config.js`) for the specified file path, or the configuration file is invalid.","error":"Error: Could not resolve a config for \"...\"."}],"ecosystem":"npm"}