Registry / testing / prettier-plugin-astro

prettier-plugin-astro

JSON →
library0.14.1jsnpmunverified

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).

npm install prettier-plugin-astro
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-AS
P
prettier-plugin-astro
testingjavascriptv0.14.1
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.

(Config)
export default { plugins: ['prettier-plugin-astro'] }
Using require() in .prettierrc.cjs without proper export
Config is not imported; the plugin is specified by name in prettier config. For TypeScript, use `import('prettier').Config` type.

Installation and configuration of prettier-plugin-astro for formatting .astro files.

// Initialize in an Astro project // 1. Install // npm i --save-dev prettier prettier-plugin-astro // 2. Create .prettierrc.mjs with: /** @type {import('prettier').Config} */ export default { plugins: ['prettier-plugin-astro'], overrides: [ { files: '*.astro', options: { parser: 'astro', }, }, ], }; // 3. Format // npx prettier --write 'src/**/*.astro'
Debug
Known issues
breakingprettier-plugin-astro v0.11.0 drops support for Prettier 2.x; only Prettier 3.x is supported.
fix
Upgrade Prettier to 3.x (npm i prettier@latest) or stick with prettier-plugin-astro <=0.10.0
affects: >=0.11.0
gotchaIf not specifying parser in overrides, Prettier may not associate .astro files with this plugin, causing formatting errors.
fix
Add overrides to your Prettier config: { files: '*.astro', options: { parser: 'astro' } }
affects: *
deprecatedThe `astro-allow-shorthand` option was renamed to `astroAllowShorthand` in recent versions.
fix
Use `astroAllowShorthand` in your Prettier config instead of the old CLI flag.
affects: >=0.14.0
breakingIn v0.12.0, line breaks and indentation inside class attributes are no longer deleted, which may change existing formatting.
fix
Review and re-format existing .astro files after upgrade.
affects: 0.12.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-astro'
Plugin not installed or not specified correctly in prettier config.
fix
Run `npm i --save-dev prettier prettier-plugin-astro` and ensure config has `plugins: ['prettier-plugin-astro']`.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier'
Prettier not installed or version incompatible.
fix
Install a compatible version of Prettier: `npm i --save-dev prettier` (3.x recommended).
Unexpected closing bracket '}'
Parser not set to 'astro', so Prettier uses a different parser (e.g., babel) for .astro files.
fix
Add override for *.astro files with parser: 'astro' in your Prettier config.
Upgrade
Version history
0.14.1latest on npm
Audit
Dependencies
prettierrequiredpeer dependency - plugin requires Prettier >=3.0
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-astro — npm install prettier-plugin-astro · libregistry