{"id":20337,"library":"prettier-plugin-astro","title":"prettier-plugin-astro","description":"Official Prettier plugin for formatting Astro (.astro) files. Current stable version 0.14.1, released October 2024, with minor/patch releases every few months. Key differentiator: it's the official Astro team plugin, supporting Astro-specific syntax like frontmatter, components, and expressions. Alternatives like prettier-plugin-astro-organize-imports offer additional sorting. Requires Node ^14.15.0 || >=16.0.0 and Prettier >=3.0 (breaking change in v0.11.0).","status":"active","version":"0.14.1","language":"javascript","source_language":"en","source_url":"https://github.com/withastro/prettier-plugin-astro","tags":["javascript","prettier-plugin","prettier","astro","formatter"],"install":[{"cmd":"npm install prettier-plugin-astro","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-astro","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-astro","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - plugin requires Prettier >=3.0","package":"prettier","optional":false}],"imports":[{"note":"Config is not imported; the plugin is specified by name in prettier config. For TypeScript, use `import('prettier').Config` type.","wrong":"Using require() in .prettierrc.cjs without proper export","symbol":"(Config)","correct":"export default { plugins: ['prettier-plugin-astro'] }"}],"quickstart":{"code":"// Initialize in an Astro project\n// 1. Install\n// npm i --save-dev prettier prettier-plugin-astro\n\n// 2. Create .prettierrc.mjs with:\n/** @type {import('prettier').Config} */\nexport default {\n  plugins: ['prettier-plugin-astro'],\n  overrides: [\n    {\n      files: '*.astro',\n      options: {\n        parser: 'astro',\n      },\n    },\n  ],\n};\n\n// 3. Format\n// npx prettier --write 'src/**/*.astro'","lang":"javascript","description":"Installation and configuration of prettier-plugin-astro for formatting .astro files."},"warnings":[{"fix":"Upgrade Prettier to 3.x (npm i prettier@latest) or stick with prettier-plugin-astro <=0.10.0","message":"prettier-plugin-astro v0.11.0 drops support for Prettier 2.x; only Prettier 3.x is supported.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Add overrides to your Prettier config: { files: '*.astro', options: { parser: 'astro' } }","message":"If not specifying parser in overrides, Prettier may not associate .astro files with this plugin, causing formatting errors.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `astroAllowShorthand` in your Prettier config instead of the old CLI flag.","message":"The `astro-allow-shorthand` option was renamed to `astroAllowShorthand` in recent versions.","severity":"deprecated","affected_versions":">=0.14.0"},{"fix":"Review and re-format existing .astro files after upgrade.","message":"In v0.12.0, line breaks and indentation inside class attributes are no longer deleted, which may change existing formatting.","severity":"breaking","affected_versions":"0.12.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm i --save-dev prettier prettier-plugin-astro` and ensure config has `plugins: ['prettier-plugin-astro']`.","cause":"Plugin not installed or not specified correctly in prettier config.","error":"Cannot find module 'prettier-plugin-astro'"},{"fix":"Install a compatible version of Prettier: `npm i --save-dev prettier` (3.x recommended).","cause":"Prettier not installed or version incompatible.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier'"},{"fix":"Add override for *.astro files with parser: 'astro' in your Prettier config.","cause":"Parser not set to 'astro', so Prettier uses a different parser (e.g., babel) for .astro files.","error":"Unexpected closing bracket '}'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}